interchange positions in a vector

조회 수: 15 (최근 30일)
Maria Lancheros Vega
Maria Lancheros Vega 2020년 11월 14일
답변: Ameer Hamza 2020년 11월 14일
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?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 14일
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개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by