Script that Accurately counts lines in a text file
이전 댓글 표시
Would someone be able to help me with a rather simple script I have to write? The script needs to be able to take a text file and count the number of lines of text. Any help is greatly appreciated!
댓글 수: 2
Bob Thompson
2019년 4월 2일
Why do you need to count the number of lines in a text file here? Many simple word processors are capable of displaying this type of information.
If you do still want a script to specifically do this, see my response to your other question about capturing certain words.
Walter Roberson
2019년 4월 2일
Is newline to be considered a line terminator or a line separator? If it is a line separator then if the last thing in a file is a newline then the emptiness between the newline and the end of file counts as a line.
답변 (2개)
Guillaume
2019년 4월 2일
linecount = sum(fileread(somefile) == 10) + 1;
See Walter's comment. This will count the emptiness between the newline and end of file as a line if the last line ends in a newline.
Will works both for Windows and Linux line ending (but not old style macs which used char(13) solely as a newline marker).
Image Analyst
2022년 8월 7일
Try this
textLines = readlines(fileName);
numLines = numel(textlines)
댓글 수: 4
faisal sani
2022년 8월 10일
@Image Analyst, I am working on a stream of images (like time series), where the images are captured by camera after illuminating with a sinusoidally modulated light source, I am interested in the response of the object captured by camera to the illuminating light source. Am I to use a one dimensional fft on each pixel location in the time series? two dimensional fft on each pixel location in the time series? or am I to use two dimensional fft on the whole image
Walter Roberson
2022년 8월 11일
What information are you hoping to extract ?
Walter Roberson
2022년 8월 11일
That question is not related to the question of how to accurately count lines in a text file. You should start your own question.
faisal sani
2022년 8월 11일
Okay, thank you, I will post my question above. The information I want to extract is how the object changes the illuminated light when reflected by adding some harmonics to the original sinusoid
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!