Mis match of dimensions

1 visualización (últimos 30 días)
Moe
Moe el 3 de Nov. de 2014
Comentada: Star Strider el 3 de Nov. de 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

Respuestas (1)

Star Strider
Star Strider el 3 de Nov. de 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 comentarios
Star Strider
Star Strider el 3 de Nov. de 2014
Getting the same error with that version:
Error using ones
Size inputs must be scalar.
Error in star (line 141415)
X2(:,:,j) = [a1(:,1), g2(:,:,j).*ones(size(a1),1)];
Star Strider
Star Strider el 3 de Nov. de 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))

Iniciar sesión para comentar.

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by