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

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...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by