Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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 Commento
Jonathan Demmer
il 21 Ago 2018
Risposte (2)
Walter Roberson
il 21 Ago 2018
0 voti
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 Commenti
Jonathan Demmer
il 21 Ago 2018
Walter Roberson
il 21 Ago 2018
Are xq and yq vectors?
It is difficult to analyze without your code and data.
Walter Roberson
il 22 Ago 2018
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
il 23 Ago 2018
Jonathan Demmer
il 22 Ago 2018
0 voti
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!