Mis match of dimensions

2 ビュー (過去 30 日間)
Moe 2014 年 11 月 3 日
コメント済み: Star Strider 2014 年 11 月 3 日
Suppose I want to find all maximum number in the matrix m:
I used this command line:
mm(:,:,j) = find( m(:,:,j) == maxlistm(:,:,j) );
If matrix m updated in each iteration, then next result for mm will be wrong. new mm dimension automatically will be match with the first mm (just repeat new maximum fined value).
Example: iteration 1:
m = [20;3;20;8;9;11;13;14;15;20];
mm = [1;3;10]
now in iteration 2, m is:
m = [2;3;2;80;9;11;13;14;15;2];
then instead of given mm = [4], it will give me:
mm = [4;4;4] % 3 rows because in the first m, it found 3 max values

回答 (1 件)

Star Strider
Star Strider 2014 年 11 月 3 日
That result is most likely because you defined ‘mm’ as a 3-D matrix.
I would define it as a cell array instead. That will allow for varying numbers of returned values from your find call.
  5 件のコメント
Star Strider
Star Strider 2014 年 11 月 3 日
I don’t have any problems opening and reading it in xlsread or opening it in Excel.
The problem is with the size argument to ones. It is always a (1xN) vector (a scalar is (1x1)), where N is the number of dimensions of the argument. These lines will throw the same error:
q = rand(5,1);
r = ones(size(q),1);
I have no idea what you’re doing, so I can’t suggest a fix for it. If you want it to be size of ‘a1’, the correct syntax is:


Community Treasure Hunt

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

Start Hunting!

Translated by