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

poster 2019-12-14 20:13

如何在MATLAB中加载这种矩阵
 
我有一个像这样的upper triangular矩阵:

A= load('A.txt'); 1.0 3.32 -7.23 1.00 0.60 1.00 我想在MATLAB中加载它,因为这是对称转换

a = A + triu(A, 1)'
所以最后我会有一个矩阵a

1.0 3.32 -7.23 3.32 1.00 0.60 -7.23 0.60 1.00 我遇到的问题是在加载时:

>> A = load('A.txt'); ??? Error using ==> load Number of columns on line 1 of ASCII file C:\A.txt must be the same as previous lines. 有没有办法做到这一点?



[B]回答:[/B]

尝试使用[URL="http://www.mathworks.com/help/techdoc/ref/importdata.html"]importdata[/URL]代替, [URL="http://www.mathworks.com/help/techdoc/ref/load.html"]加载[/URL]通常仅用于[I].mat[/I]文件。您的文件[I]A.txt的[/I]结构如何?如果是这样

1.0 3.32 -7.23 1.00 0.60 1.00 那么你会得到

A = importdata('A.txt') A = 1.0000 3.3200 -7.2300 1.0000 0.6000 NaN 1.0000 NaN NaN 因此,您将不得不像这样移动最后两行

A(2,:) = circshift(A(2,:),[0 1]) A(3,:) = circshift(A(3,:),[0 2]) A = 1.0000 3.3200 -7.2300 NaN 1.0000 0.6000 NaN NaN 1.0000 然后将NaN替换为0,然后使用表达式创建对称矩阵。

A(isnan(A)) = 0; a = A + triu(A, 1)'; A = 1.0000 3.3200 -7.2300 3.3200 1.0000 0.6000 -7.2300 0.6000 1.0000

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


所有时间均为北京时间。现在的时间是 10:59

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