필터 지우기
필터 지우기

how to interchange array elements

조회 수: 3 (최근 30일)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2013년 3월 28일
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개)

Andrei Bobrov
Andrei Bobrov 2013년 3월 28일
x = [11 12 13 14 15];
y = x;
y([end,1]) = y([1,end]);

Honglei Chen
Honglei Chen 2013년 3월 28일
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
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2013년 3월 28일
no. first element and last element should be interchanged is my objective..
Cedric
Cedric 2013년 3월 28일
y = [x(end), x(2:end-1), x(1)] ;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by