在MATLAB中导入带注释的文本文件

dev*_*ium 4 import file-io matlab comments file

从文本文件导入数据时,MATLAB是否将任何字符或字符组合解释为注释?当它在一行的开头检测到它时,会知道所有的行都要忽略吗?

我在文件中有一组看起来像这样的点: alt text http://img209.imageshack.us/img209/5139/ysabyc2tn4aeig0jvxotibd.png 正如你所看到的,他似乎并不太了解它们.除了我可以使用MATLAB知道忽略之外还有什么吗?

谢谢!

Amr*_*mro 10

实际上,您的数据不一致,因为每行必须具有相同的列数.

1)

除此之外,importdata将正确识别使用'%'作为注释:

FILE.DAT

%12 31
12 32
32 22
%abc
13 33
31 33
%ldddd
77 7
66 6
%33 33
12 31
31 23
Run Code Online (Sandbox Code Playgroud)

MATLAB

data = importdata('file.dat')
Run Code Online (Sandbox Code Playgroud)

2)

否则使用textscan指定任意注释符号:

File2.DAT的

//12 31
12 32
32 22
//abc
13 33
31 33
//ldddd
77 7
66 6
//33 33
12 31
31 23
Run Code Online (Sandbox Code Playgroud)

MATLAB

fid = fopen('file2.dat');
data = textscan(fid, '%f %f', 'CommentStyle','//', 'CollectOutput',true);
data = cell2mat(data);
fclose(fid);
Run Code Online (Sandbox Code Playgroud)