Error ' Assignment has more non-singleton rhs dimensions than non-singleton..'

I want to find the location of maximum 'EC' in the first direction. Here is the code I used to find so.
for ii=1:size(EC,2);
ss(1,ii,:)=max(EC(:,ii,:),[],1);
loc(1,ii,:) = find(EC(:,ii,:) == ss(1,ii,:));
end
but an error ' Assignment has more non-singleton rhs dimensions than non-singleton subscripts' keeps coming. Can anyone tell me what to do with it?

5 comentarios

Does it occur on the max() or on the find() ?
You have not indicated whether the array is 2D or more. If it is 2D then EC(:,ii,:) would be the same as EC(:,ii) and then max() of that would be a scalar and could be stored in a scalar ss(1,ii,:). Then in the find(), EC(:,ii,:) would be EC(:,ii) a vector, and that could be tested against the scalar ss(1,ii) giving a vector result for the "==". find() on that vector result could result in a scalar (if the max was unique) or could result in a vector (if there were multiple copies of the maximum.)
If, though, EC has more than 2 dimensions, then max(EC(:,ii,:),[],1) would return an array whose first two dimension were and whose third dimension is the product of the remaining dimensions after the second. e.g., if EC was 2 x 3 x 4 x 5 then the max() would be 1 x 1 x (4*5). As this would be a vector, you would be able to store it into ss(1,ii,:). But then in the find(), EC(:,ii,:) would be size(EC,1) by 1 by the product of the dimensions after the second, and you would not be able to "==" that against the vector ss(1,ii,:) unless the first dimension of EC happened to be 1.
It occurs on find(). EC is 3D.
is there any alternative to finding the 'loc' then?
If you are trying to find the maximum of each column along with the associated indices, use the two-output version of max()
[ss(1,ii,:), loc(1,ii,:)] = max(EC(:,ii,:),[],1);
However you need to decide which index you want returned if there are multiple copies of the maximum in any given column.
Thank you very much...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by