swiching elements of same vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
jean claude
el 6 de Abr. de 2016
Editada: jean claude
el 6 de Abr. de 2016
hi everybody, i have vector
X=[ 20; 0; 0;0; 100; 0;0;0;50];
i would like to have
X=[0;0;0;0;20;0;0;0;100];
so that each number take the next number case
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 6 de Abr. de 2016
X=[ 20; 0; 0;0; 100; 0;0;0;50]
ii=find(X~=0)'
idx=circshift(ii,[0 1])
X(ii(2:end))=X(idx(2:end))
X(ii(1))=0
Más respuestas (1)
Jos (10584)
el 6 de Abr. de 2016
Editada: Jos (10584)
el 6 de Abr. de 2016
Easy:
X = [20 0 0 0 100 0 0 50 0]'
[i,~,v] = find(X)
X(i) = [0 ; v(1:end-1)]
1 comentario
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!