Error using reshape - Please help!

2 visualizaciones (últimos 30 días)
Maria Y
Maria Y el 22 de En. de 2019
Comentada: Maria Y el 22 de En. de 2019
Trying to create this out put variable but I'm getting an error saying "to RESHAPE the number of elements must not change". Please help!
datadir = cd; % define current path
filename = uigetfile('SSRT_results.xlsx');
[~, ~, raw] = xlsread(filename,'Sheet1','A2:G321');
stringVectors = string(raw(:,3));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,[1,2,4,5,6,7]);
data = reshape([raw{:}],size(raw));
  5 comentarios
Kevin Phung
Kevin Phung el 22 de En. de 2019
Can you describe how you actually want to reshape the raw data?
because it just seems like youre trying to set data = raw.
raw is your 320x7 matrix, as described by walter.
but in your first argument in reshape, raw{:} is just raw turned into a column vector... and your second argument looks like youre just trying to reshape that column vector back into a 320x7.
Maria Y
Maria Y el 22 de En. de 2019
I was able to figure out my issue (something wrong with the excel file), thank you so much for your help!!

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 22 de En. de 2019
The number of elements in the cell array raw is not necessarily the same as the number of elements contained in those cells. In this example the three element cell array raw contains nine numbers.
raw = {[1 2 3], [4 5 6], [7 8 9]}
combine = [raw{:}]
size(combine)
size(raw)
Imagine you had a dresser with three drawers, each of which contained two pieces of clothing. You have three drawers but six pieces of clothing in total.
What would you expect / intend this line of code to do for the raw cell array I created above? What is the exact result you want?
data = reshape([raw{:}],size(raw));
  1 comentario
Walter Roberson
Walter Roberson el 22 de En. de 2019
In the case that each element of the cell array contains a scalar numeric value (including nan), then [raw{:}] will have the same number of elements as raw has.
However, if even one of the elements contains a character vector with more than one character, or contains the empty character vector, then [raw{:}] will have a different number of elements than raw does.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by