How can I read the entire contents of a file into a cell array with one line per cell?

조회 수: 15 (최근 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
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개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by