Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello all,
I tried to run a particle tracking model on matlab. When i try to run the code below:
clear I J u v u1 u2 v1 v2
I = find(xq<x(it,ip),1);
J = find(yq<y(it,ip),1);
u1 = MASK(J,I).*U(J,I);
v1 = MASK(J,I).*V(J,I);
% advection:
ddx = u1*1800;%m.DT;
ddy = v1*1800;%m.DT;
an error message appears saying:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in PTM_northMenai - Copy (line 141)
x(it+1,ip) = x(it,ip)+ ddx;
However if i change the sign < for > it works properly!! I would like to know if someone could explain it to me and how could I fix it?
Thank you very much all
댓글 수: 1
답변 (2개)
Walter Roberson
2018년 8월 21일
If the find() does not find anything then it returns empty, which results in empty when used as an index, which results in ddx and ddy being empty. When you add the empty ddx to a value you get empty. You then try to store the empty results in a location with size 1, but that doesn't fit.
댓글 수: 4
Walter Roberson
2018년 8월 22일
Instead of looping over it and ip, you can use something like
[~, xbin] = histc(x, qx);
[~, ybin] = histc(y, qy);
ind = sub2ind(size(MASK), ybin, xbin);
u1 = MASK(ind) .* U(ind);
v1 = MASK(ind) .* V(ind);
ddx = u1*1800;%m.DT;
ddy = v1*1800;%m.DT;
Watch out for the boundary conditions: x values outside the range xmin to xmax is obvious, but the behaviour at xmax can be a problem. histc() gives the last entry a bin all of its own.
The newer
[~, ~, xbin] = histcounts(x, qx);
would treat the upper bound exactly as part of the previous bin.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!