swiching elements of same vector
Show older comments
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
Accepted Answer
More Answers (1)
Jos (10584)
on 6 Apr 2016
Edited: Jos (10584)
on 6 Apr 2016
Easy:
X = [20 0 0 0 100 0 0 50 0]'
[i,~,v] = find(X)
X(i) = [0 ; v(1:end-1)]
1 Comment
jean claude
on 6 Apr 2016
Edited: jean claude
on 6 Apr 2016
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!