Read in the whole file at once. In this example I'm using fileread() because I'm unfamiliar with the FEX submission readfile() mentioned in your question.
C = fileread('myTextFile.txt');
Split the char array by lines into a cell array
Ca = strsplit(C,newline);
Extract text lines n to m
If you'd rather have a char array as output
7 Comments
Kumar (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766029
vaya putra (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766035
Adam Danz (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766037
vaya putra (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766041
Adam Danz (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766049
vaya putra (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766063
Adam Danz (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/490435-read-txt-and-write-in-matab#comment_766085
Sign in to comment.