Id there a way to recognize blank lines when you are scanning a textfile in Matlab? I want to parse the files based on the blank lines in between the text. Is this possible?
+1
A:
Yes, it's possible. A MATLAB snippet would look something like:
fid = fopen('reader.m');
newline = sprintf('\r\n');
line = fgets(fid);
while ischar(line)
if strcmp(newline, line)
disp('Empty line');
else
disp('Non-empty line');
end
line = fgets(fid);
end
Reinderien
2010-06-16 22:14:43
I think he said "Matlab"...
Drew Hall
2010-06-16 22:17:15
+1
A:
Here's one possibility:
fid = fopen('myfile.txt');
lines = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
lines = lines{1};
% lines now contains a cell array of strings,
% one per line in the file.
% Find all the blank lines using cellfun:
blank_lines = find(cellfun('isempty', lines));
Steve Eddins
2010-06-17 00:30:27