How to Solve RESHAPE Function Error
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
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
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
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.
参考
カテゴリ
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!