How to Solve RESHAPE Function Error

1 view (last 30 days)
Khaled AbdEldayem
Khaled AbdEldayem on 30 Jun 2017
Commented: Walter Roberson on 1 Jul 2017
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 Comment
Walter Roberson
Walter Roberson on 30 Jun 2017
That looks like it should work, but at the time of failure please show us the output of
size(plmprofile1)
nyint
nxint

Sign in to comment.

Answers (2)

James Tursa
James Tursa on 30 Jun 2017
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 Comments
Khaled AbdEldayem
Khaled AbdEldayem on 30 Jun 2017
the variables contain the values as 8 bit integers
Walter Roberson
Walter Roberson on 1 Jul 2017
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

Sign in to comment.


Image Analyst
Image Analyst on 1 Jul 2017
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 Comments
Image Analyst
Image Analyst on 1 Jul 2017
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 on 1 Jul 2017
I could not read the file at all in MATLAB on my Mac.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!