Mis match of dimensions

4 views (last 30 days)
Moe
Moe on 3 Nov 2014
Commented: Star Strider on 3 Nov 2014
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];
then:
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

Answers (1)

Star Strider
Star Strider on 3 Nov 2014
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 Comments
Star Strider
Star Strider on 3 Nov 2014
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:
ones(size(a1))

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by