채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 10월 17일
편집: Andrei Bobrov 2013년 10월 17일

0 개 추천

Z([1,2]) = Z([2,1]);
ADD
Z = [2
4
2
1
7
9
1
1]; % new case
a = [1, 2]; % replacement value
[l,ii] = ismember(Z,a);
Z(l) = a(3-ii(l));

댓글 수: 2

Anusha
Anusha 2013년 10월 17일
how to swap 1st and 3rd position
Z([1,3]) = Z([3,1]);

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

추가 답변 (1개)

dpb
dpb 2013년 10월 17일

0 개 추천

Z(1:3)=flipud(Z(1:3));
Only works because of odd number, of course. In general to swap individual elements will still take the temporary to hold the one element while overwrite the other.

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2013년 10월 17일

편집:

2013년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by