在 OP 更准确地指定他想要的内容之后编辑答案:)
在调用textscan时,可以使用选项HeaderLines跳过前13行,与official documentation一致。
假设文件是 OP 提供的文件,则调用它test.txt,下面的代码就可以了。
% read the text file original text file
orig = fileread('test.txt');
% replace commas with dots
newfile = strrep(orig,',','.');
% create a new text file in write mode
fid_w = fopen('test_mod.txt','w')
% write this modified version of the file to disk
fprintf(fid_w,'%s',newfile);
% close this text file
fclose(fid_w)
% open the modified text file in read mode
fid_r = fopen('test_mod.txt','r');
% put the data in a cell array, assuming strings and skipping the
% first 13 lines
indata = textscan(fid_r, '%s', 'HeaderLines',13, 'Delimiter', '\r');
% close the modified text file
fclose(fid_r);
% cell --> char
indata = cell2mat(indata{1});
% char --> number
indata = str2num(indata)
这应该是寻求的输出:
indata =
0 0.1048
0 0.1048
0 0.1048
0 0.1048
我也发布了whos indata 的输出:
Name Size Bytes Class Attributes
indata 4x2 64 double
哦,当然indata 包含整个0.104797 数字,它只是四舍五入到小数点后四位。如果您想查看完整的输出,只需发出format long。有关format 的更多信息,请访问official docs。