Borrar filtros
Borrar filtros

problem with assigning in loop

1 visualización (últimos 30 días)
Hamid
Hamid el 13 de Dic. de 2014
Editada: Matt J el 13 de Dic. de 2014
Hi everybody, I want to assign every minrow to Ep but Ican't and only last row gets number and other rows gets zero.
What should I do?
this is my code; Thank you guys.
u=0;
for i=1:ne
Le(i)=sqrt((Ex(i,1)-Ex(i,2))^2+(Ey(i,1)-Ey(i,2))^2+(Ez(i,1)-Ez(i,2))^2);
if Le(i)~=0
u=u+1;
[ minval , minidx ] = min(available(available(:, 6) > Le(i)/20000, 6));
minrow = available(minidx, :);
Ep=zeros(u,6);
Ep(u,:)=minrow;
end
end

Respuesta aceptada

Matt J
Matt J el 13 de Dic. de 2014
Get rid of the line
Ep=zeros(u,6);
  2 comentarios
Hamid
Hamid el 13 de Dic. de 2014
it works, thank you.
Matt J
Matt J el 13 de Dic. de 2014
Editada: Matt J el 13 de Dic. de 2014
The code is still less than ideal, though. Why not compute Le with vectorized methods in advance of the loop so you can figure out how to pre-allocate Ep properly?
Le=sqrt((Ex(:,1)-Ex(:,2))^2+(Ey(:,1)-Ey(:,2))^2+(Ez(:,1)-Ez(:,2))^2);
Lenz=nonzeros(Le(1:ne));
Ni=length(Lenz);
Ep=zeros(Ni,6);
for i=1:Ni
[ minval , minidx ] = min(available(available(:, 6) > Lenz(i)/20000, 6));
minrow = available(minidx, :);
Ep(i,:)=minrow;
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by