reshape function error on number of elements

Hi I have the following code
The error appears on the line of "B", however I think that A has 8760 elements and B = 365 x 24 which also is 8760. What could be going wrong?
A = squeeze(hourly_surplus(1,1,1,:));
B = reshape(A,365,24);
Where size(A) = 8760 x 1
however I get the error
Error using reshape
To RESHAPE the number of elements must not change
Thanks

1 件のコメント

Star Strider
Star Strider 2012 年 10 月 14 日
編集済み: Star Strider 2012 年 10 月 14 日
This works fine for me:
hs = rand(4,4,4,8760);
A = squeeze(hs(1,1,1,:));
B = reshape(A, 365,24);
elms = [numel(hs); numel(A); numel(B)]
I suggest you set a breakpoint at the line that defines A and look at the workspace variables. Something obviously isn't working the way it should.

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

回答 (1 件)

Wayne King
Wayne King 2012 年 10 月 14 日
編集済み: Wayne King 2012 年 10 月 14 日

1 投票

What do you mean, "you think"? How about just determining the exact size of A.
size(A)
then you will know exactly how big A is.

4 件のコメント

Andrew Alkiviades
Andrew Alkiviades 2012 年 10 月 14 日
size(A) = 8760 x 1
Wayne King
Wayne King 2012 年 10 月 14 日
Something appears to be wrong somewhere because
A = randn(10,10,10,8760);
A = squeeze(A(1,1,1,:));
B = reshape(A,365,24);
should definitely work. Can you copy and paste the above code in your workspace and see that it works?
Andrew Alkiviades
Andrew Alkiviades 2012 年 10 月 14 日
yes I have tried you example and it works!
Wayne King
Wayne King 2012 年 10 月 14 日
Then something must be happening inside the program, as star strider suggested above set a breakpoint on the line
B = reshape(A, 365,24);
and then query
size(A)
at the command line, or hover your cursor over the variable A.

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2012 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by