在MATLAB中导入带注释的文本文件 [英] Importing text files with comments in MATLAB

查看:766
本文介绍了在MATLAB中导入带注释的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there any character or character combination that MATLAB interprets as comments, when importing data from text files? Being that when it detects it at the beginning of a line, will know all the line is to ignore?

我有一组文件中的点,看起来像这样:

正如你可以看到他似乎没有了解他们很好。除了//我可以使用MATLAB知道它是忽略吗?

I have a set of points in a file that look like this: And as you can see he doesn't seem to understand them very well. Is there anything other than // I could use that MATLAB knows it's to ignore?

谢谢!

推荐答案

如果您使用 textscan ,您可以将 CommentStyle 参数设置为 // 。尝试这样:

If you use the function textscan, you can set the CommentStyle parameter to // or %. Try something like this:

fid = fopen('myfile.txt');
iRow = 1;
while (~feof(fid)) 
    myData(iRow,:) = textscan(fid,'%f %f\n','CommentStyle','//');
    iRow = iRow + 1;
end
fclose(fid);

如果每行有两个数字,这将工作。我注意到在你的例子中每行的数字数量不同。有一些只有一个数字的行。这是您的数据的代表吗?如果每行中没有统一的列数,则必须采用不同的处理方式。

That will work if there are two numbers per line. I notice in your examples the number of numbers per line varies. There are some lines with only one number. Is this representative of your data? You'll have to handle this differently if there isn't a uniform number of columns in each row.

这篇关于在MATLAB中导入带注释的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆