swap the values in matrix
3 次查看(过去 30 天)
显示 更早的评论
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
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
2014-1-24
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;
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!