Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (2)
Walter Roberson
el 21 de Ag. de 2018
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 comentarios
Walter Roberson
el 22 de Ag. de 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.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!