Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

1 回表示 (過去 30 日間)
Jonathan Demmer
Jonathan Demmer 2018 年 8 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Jonathan Demmer
Jonathan Demmer 2018 年 8 月 21 日
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;

回答 (2 件)

Walter Roberson
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
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.
Jonathan Demmer
Jonathan Demmer 2018 年 8 月 23 日
Thank you all for your answer!! Thje problem is solved!

Jonathan Demmer
Jonathan Demmer 2018 年 8 月 22 日
I know sorry but the code is really long that is why i did not copy it...
xq and yq are define as: dx = 50; dy = 50; xq = xmin : dx : xmax; yq = ymin : dy : ymax;
Where xmin, xmax, ymin and ymax are UTM coordinates value

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by