Extracting the first three minimum elements from a vector v and assign them to h then letter remove the elements from vector v and used the index to removed some element in vector w.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bashir Yusuf Bichi
el 6 de Dic. de 2017
Respondida: KSSV
el 6 de Dic. de 2017
v=[3,6,1,7,9,4];
w=[3,2,7,1,9,5];
[x,y]=sort(v);
h=x(1:3);
i=1;
while i<=numel(v)
if v(i)==h(i) % here h will be less than the elements in v, so it give me error
v(i)=[];
else
v(i)=v(i);
end
i=i+1;
trying to take the first three minimum elements in vector v and assigned the values to h, and after then, remove those elements from v, and use index of the removed elements of v, to remove some elements in w.
e.g v=
6 comentarios
Respuesta aceptada
Bashir Yusuf Bichi
el 6 de Dic. de 2017
Editada: Bashir Yusuf Bichi
el 6 de Dic. de 2017
0 comentarios
Más respuestas (1)
KSSV
el 6 de Dic. de 2017
v=[3,6,1,7,9,4];
[k,idx] = sort(v) ;
h = k(1:3) ;
%%Remove from k
k(1:3) = []
%%Remove from v
v(idx(1:3))=[]
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!