reshape function error on number of elements
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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
2012년 10월 14일
편집: Wayne King
2012년 10월 14일
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!