Hello,
I have a matrix
[2 3 4 5 6 7]
a=2
b=3
i want to swap two values
ans is
[3 2 4 5 6 7]

댓글 수: 1

Raihan Ahmed
Raihan Ahmed 2015년 8월 22일
Easy Method to do this is swapping Using index
b=[2:7]; b=b([2,1,3:end]);
this will give you the result :)

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

 채택된 답변

ES
ES 2014년 1월 24일

0 개 추천

InMtx=[2 3 4 5 6 3 3 4 2];
a=2;
b=3;
Twos=InMtx==a;
Threes=InMtx==b;
InMtx(Twos)=b;
InMtx(Threes)=a;

추가 답변 (1개)

Neel Shah
Neel Shah 2019년 11월 1일

0 개 추천

how to swap element in the 3*3 matrix
like a(2,1)=a(4,3)
a(4,3)=a(2,1)

카테고리

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

태그

질문:

2014년 1월 24일

답변:

2019년 11월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by