interchange positions in a vector

I have a vector let's say y = [1 2 3 4] and I want my next output to be y = [2 3 4 1] and then y = [3 4 1 2].
how can I do that without a for?

 采纳的回答

You can use circshift
y = [1 2 3 4];
y1 = circshift(y, -1);
y2 = circshift(y, -2);
Result
>> y1
y1 =
2 3 4 1
>> y2
y2 =
3 4 1 2

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Vehicle Dynamics Blockset 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by