How to do column or row swapping or interchange in a matrix?

80 次查看(过去 30 天)
Hi,
IFor example, In a matrix A = 3x5 , I want to swap complete column 2 with column 5.
How can i do that. Is there any in-built function or code?

采纳的回答

Voss
Voss 2021-12-27
A(:,[5 2]) = A(:,[2 5]);

更多回答(1 个)

Yusuf Suer Erdem
Yusuf Suer Erdem 2021-12-26
Try these codes below please;
A = [1, 2, 3, 4, 5; 4, 5, 6, 7, 8; 9, 10, 11, 12, 13]
v = A(:, 2);
A(:, 2) = A(:, 5);
A(:, 5) = v;
A
  2 个评论
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2021-12-26
Thanks u.
I have this idea but searching for some inbuilt function.
Thanks again.
Yusuf Suer Erdem
Yusuf Suer Erdem 2021-12-27
Hello use my codes below please. If this answer does your job, accept my answer please. After my research, i could not find a specific function just for this purpose.
A=[1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15];
A
A = A(:,[1 5 3 4 2])

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by