你可以做类似的事情
fid = fopen('file.txt', 'r');
s = textscan(fid, '%s', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
fclose(fid);
result = str2double(s{1}).';
这使用空间作为分隔符。结果是一个行向量,其中任何非数字都被转换为NaN
. 对于您的示例文件,
result =
Columns 1 through 6
0.003160470000000 0.001899920000000 0.001867910000000 0.001703660000000 0.001456770000000 0.002069700000000
Columns 7 through 12
0.003160470000000 0.002873780000000 0.002266450000000 1.000000000000000 85.163700000000006 44.949599999999997
Columns 13 through 18
59.073799999999999 74.456999999999994 82.415899999999993 NaN 51.987499999999997 54.782200000000003
Columns 19 through 20
85.163700000000006 1.000000000000000