How can I read the entire contents of a file into a cell array with one line per cell?
13 次查看(过去 30 天)
显示 更早的评论
I would like to read the entire contents of a file. In the end, I'd like to have a cell array, where each cell contains a line from the file.
采纳的回答
MathWorks Support Team
2009-6-27
There is no single function that does this in MATLAB, although several functions can be combined to do this.
For instance,
str = fileread('foo.txt');
lines = regexp(str, '\r\n|\r|\n', 'split');
reads "foo.txt" into a string, and then splits the string into cells according to newline combinations.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!