how to swap this matrix
1 次查看(过去 30 天)
显示 更早的评论
i have this column of matrix
Z= 2
4
1
7
9
how to swap this 1 and 2
0 个评论
采纳的回答
Andrei Bobrov
2013-10-17
编辑:Andrei Bobrov
2013-10-17
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 个评论
更多回答(1 个)
dpb
2013-10-17
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Compiler SDK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!