MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB交换两个不同矩阵的列 (https://www.labfans.com/bbs/showthread.php?t=24023)

poster 2019-12-10 20:48

MATLAB交换两个不同矩阵的列
 
我正在使用matlab,遇到了一些困难。我正在尝试将一个矩阵(A)的列与另一矩阵(B)的列交换。例如:

A =

4 6 5 7 8 4 6 5 9 1 0 0 0 1 0 0 0 1 B =

1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 有没有办法告诉Matlab切换例如A中的第1列和B中的第3列?



[B]回答:[/B]

实际上,您可以使用[URL="http://www.mathworks.com/help/techdoc/ref/deal.html"]DEAL[/URL]函数在一行中执行此列交换,而不需要虚拟变量:

[A(:,1),B(:,3)] = deal(B(:,3),A(:,1));

[url=https://stackoverflow.com/questions/3973360]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 20:30

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.