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=23356)

poster 2019-12-10 20:41

MATLAB中是否有任何用于更改矩阵形式的函数?
 
我必须考虑以下规则,通过更改已知矩阵的形式来获取未知矩阵:

H = [-P'|I] %' G = [I|P] 哪里
[LIST][*] H是已知矩阵[*] G是必须计算的未知矩阵[*]我是身份矩阵[/LIST]例如,如果我们有一个矩阵,

H = [1 1 1 1 0 0; 0 0 1 1 0 1; 1 0 0 1 1 0] 其形式必须更改为

H = [1 1 1 1 0 0; 0 1 1 0 1 0; 1 1 0 0 0 1] 所以

-P' = [1 1 1; 0 1 0; 1 1 0] 在二元矩阵-P = P情况下。

因此

G = [1 0 0 1 1 1; 0 1 0 0 1 0; 0 0 1 1 1 0] 我知道如何通过执行基本的行操作在纸上解决问题,但尚未弄清楚如何使用MATLAB解决问题。

解决给定问题的方法是什么?



[B]回答:[/B]

如果-P'中的列顺序无关紧要,这是使用函数[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ismember.html"]ISMEMBER[/URL]的一种解决方案:

>> H = [1 1 1 1 0 0; 0 0 1 1 0 1; 1 0 0 1 1 0]; %# From above >> pColumns = ~ismember(H',eye(3),'rows') %'# Find indices of columns that %# are not equal to rows pColumns = %# of the identity matrix 1 0 1 1 0 0 >> P = -H(:,pColumns)' %'# Find P P = -1 0 -1 -1 -1 0 -1 -1 -1 >> G = logical([eye(3) P]) %# Create the binary matrix G G = 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 1 1 1 [B]注意:[/B]此解决方案将适用于H整数或二进制值。如果H具有浮点值,则在使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ismember.html"]ISMEMBER[/URL]时,您可能会遇到浮点比较的问题(有关此问题的更多讨论,请参见[URL="https://stackoverflow.com/questions/2669942/problem-using-the-find-function-in-matlab"]此处[/URL]和[URL="https://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab"]此处[/URL] )。



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


所有时间均为北京时间。现在的时间是 04:58

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