how to interchange array elements

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.?

回答(2 个)

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 个评论

no. first element and last element should be interchanged is my objective..
y = [x(end), x(2:end-1), x(1)] ;

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by