Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件 data.txt
1 22 34 -2 3 34 -3 2 3 43 -3 2 3
我想将此文件作为单独的矩阵加载到 Octave
matrix1 = [1; 22; 34 ;-2] matrix2 = [3; 34 -3] . . .
我该怎么做呢?我试过 fopen 和 fgetl,但似乎每个字符在矩阵中都有自己的位置。我想分隔值,而不是字符(它是空格分隔的)。
又快又脏:
A = dlmread("file"); matrix = 1; # just for nice varname generation for i = 1:size(A,1) name = genvarname("matrix",who()); eval([name " = A(i,:);"]); eval(["[_,__," name "] = find(" name ");"]); end clear _ __ A matrix i
格式需要与您指定的相同。