Error using reshape - Please help!

조회 수: 5 (최근 30일)
Maria Y
Maria Y 2019년 1월 22일
댓글: Maria Y 2019년 1월 22일
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
Kevin Phung
Kevin Phung 2019년 1월 22일
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 2019년 1월 22일
I was able to figure out my issue (something wrong with the excel file), thank you so much for your help!!

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2019년 1월 22일
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
Walter Roberson
Walter Roberson 2019년 1월 22일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by