How to Solve RESHAPE Function Error

조회 수: 3 (최근 30일)
Khaled AbdEldayem
Khaled AbdEldayem 2017년 6월 30일
댓글: Walter Roberson 2017년 7월 1일
I am trying to use a reshape function
If i use this syntax
plmprofile1=reshape(plmprofile1,90,180);
the function works well but i am trying to make this function more dynamic so when i created two integer variables nxint = 180 and nyint = 90
and using this syntax
plmprofile1=reshape(plmprofile1,nyint,nxint);
the code didn't work well and this error appeared
To RESHAPE the number of elements must not change.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 6월 30일
That looks like it should work, but at the time of failure please show us the output of
size(plmprofile1)
nyint
nxint

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

답변 (2개)

James Tursa
James Tursa 2017년 6월 30일
Either:
1) The total number of elements of plmprofile1 is different between the reshape(plmprofile1,90,180) call and the reshape(plmprofile1,nyint,nxint) call
or
2) The variables nyint and nxint really don't contain the values you think they do.
To debug this problem, do the following. At the command line prompt issue the following:
dbstop if error
Then run your code. When the error is encountered, the code will pause with all variables intact. Examine size(plmprofile1) and the values of nyint and nxint to see what is really going on.
  댓글 수: 3
Khaled AbdEldayem
Khaled AbdEldayem 2017년 6월 30일
the variables contain the values as 8 bit integers
Walter Roberson
Walter Roberson 2017년 7월 1일
It does not seem to make any difference in my tests whether the size variables are uint8 or double.
Please go through the debugging steps I indicated, showing us
size(plmprofile1)
nyint
nxint

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


Image Analyst
Image Analyst 2017년 7월 1일
It works fine for me, either with numbers or variables:
% Create an array with 16,000 elements.
plmprofile1 = rand(45, 360);
% Reshape to 90 by 180.
plmprofile1a = reshape(plmprofile1, 90, 180);
% Reshape to 90 by 180.
nxint = 180
nyint = 90
plmprofile1b = reshape(plmprofile1, nyint, nxint);
What did you do differently?
  댓글 수: 5
Image Analyst
Image Analyst 2017년 7월 1일
You could be right. When I said
nxint = 180
nyint = 90
and asked the difference, and he said "nxint and nyint are float numbers not integer" I assume he meant that he had fractional parts off the integer, because everyone knows (or should know) that saying the above means that the variables are floating point doubles, even if they store integer values. Though maybe Khaled didn't know that.
But like Walter, in my tests, with the original uploaded resolution I didn't encounter any black frames. If Khaled wants to dive into it more then he might have to open a case with tech support since neither of us can reproduce his problem.
Walter Roberson
Walter Roberson 2017년 7월 1일
I could not read the file at all in MATLAB on my Mac.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by