Error in using reshape

the error stated: Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
i'm doing a reshape in producing a taylor diagram. im using the same script but now it's not working because of this reshape issue.
i used reshape as follows;
for observation data;
dimN = length(size(getOBS));
xbox = size(getOBS, dimN-1);
ybox = size(getOBS, dimN );
data = ones(length(exp)+1,xbox*ybox);
data(1,:) = reshape(squeeze(getOBS),1,xbox*ybox);
for experiment;
data(expcount+1,:) = reshape(squeeze(getDAT),1,xbox*ybox);
previously i did the same for a different set of experiments, and did not have any issues. do you know how i can fix this?
the script is attahced

8 件のコメント

Sharifah Omar
Sharifah Omar 2022 年 12 月 5 日
i have 28 experiments ,against 1 obervation
Image Analyst
Image Analyst 2022 年 12 月 5 日
What does this show in the command window:
temp = squeeze(getDAT);
size(temp)
numel(temp)
xbox*ybox
fprintf('Number of columns in data = %d.\n', size(data, 2));
cr
cr 2022 年 12 月 5 日
Perhaps you now have singleton dimensions while you didn't earlier?
Sharifah Omar
Sharifah Omar 2022 年 12 月 5 日
編集済み: Sharifah Omar 2022 年 12 月 5 日
@Image Analyst unrecognized function of getDAT
it also says the same error of reshape
Voss
Voss 2022 年 12 月 5 日
@Sharifah Omar: getDAT is cleared at the end of the big for loop in your script (line 144), along with data and getOBS:
clear data getOBS getDAT
so you won't be able to get any info about them after that.
Try commenting-out that line, run the script again, and then tell us what running these commands gives you:
size(getOBS)
expcount
size(getDAT)
Sharifah Omar
Sharifah Omar 2022 年 12 月 6 日
@Voss it still shows the same error; reshape
Voss
Voss 2022 年 12 月 6 日
Please tell us the size of getOBS, the value of expcount, and the size of getDAT.
Image Analyst
Image Analyst 2022 年 12 月 6 日
When I run your script, I get this:
>> Copy_of_DJF_region1
Unrecognized function or variable 'nc_varget'.
Error in Copy_of_DJF_region1 (line 33)
getOBS = nc_varget('ERA5_DJF_north.nc',var{varcount});
Please attach that nc_varget() function and the file called 'ERA5_DJF_north.nc'

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2022 年 12 月 6 日

0 投票

The error is simple....you are trying to reshape more number of elements than present in the matrix.
EXample:
A = rand(9,1) ;
B = reshape(A,3,3) ; % as nine lements present in A, you can have 3,3 combination. Nothing lese combination possilbe
C = reshape(A,2,4) ; % error. You cannot have eight elements from nine. If you want to have
D = reshape(A(1:8),2,4) ; % here eight elements are picked and reshaped into eight elements
Note: If A has m*n elements. You can reshape A into m1,n1 so that m1*n1 = m*n.

カテゴリ

ヘルプ センター および File ExchangeParticle & Nuclear Physics についてさらに検索

質問済み:

2022 年 12 月 5 日

コメント済み:

2022 年 12 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by