问题描述
我正在尝试使用以下
file_content = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '')
但这只会返回
file_content =
{0x1 cell}
实际上我的文件有224行.因此,如果我使用
when actually my file has 224 line. so if i use
file_content = textscan(fid,'%s',224,'delimiter','\n')
我了解所有情况
file_content =
{224x1 cell}
什么是读取.m文件中所有数据(主要是字符串)的更合适方法?谢谢
what will be a more proper way to read all the data(mostly strings) in a .m file?thanks
推荐答案
由于您没有列出您的需要(您正在阅读一个大文件吗?许多小文件吗?速度是一个问题吗?您真正想要做什么? )我给你最简单的答案:
Since you do not list your needs (are you reading a huge file?, many small files? is speed an issue? what do you really want to do?) I'm giving you the simplest possible answer:
您这样做:
f = fopen('data.txt');
g = textscan(f,'%s','delimiter','\n');
fclose(f);
请记住在阅读后关闭,否则您将无法再次阅读.
remember to close after reading, because otherwise you won't be able to read again.
您可以将第一行作为g {1} {1},将第二行作为g {1} {2},依此类推.
You can get the first line as g{1}{1}, the second as g{1}{2} and so on.
这是 textscan 的matlab文档,其中提供了更多内容详细信息.
Here is the matlab documentation for textscan which gives a lot more details.
这篇关于如何进行文本扫描以读取文件中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!