how to interchange array elements
Show older comments
my input is x=[11 12 13 14 15]. my output should be y=[15 12 13 14 11]. how to interchange particular values without disturbing other elements.?
Answers (2)
Andrei Bobrov
on 28 Mar 2013
x = [11 12 13 14 15];
y = x;
y([end,1]) = y([1,end]);
Honglei Chen
on 28 Mar 2013
Not sure if this is what you are looking for, but here is one way to do it, as long as you know the order
y = x([5 2 3 4 1])
2 Comments
Sivakumaran Chandrasekaran
on 28 Mar 2013
Cedric
on 28 Mar 2013
y = [x(end), x(2:end-1), x(1)] ;
Categories
Find more on Matrix Indexing 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!