Matlab에서 텍스트 파일을 스캔 할 때 빈 줄을 인식하는 방법이 있습니까? 텍스트 사이의 빈 줄을 기반으로 파일을 구문 분석하고 싶습니다. 이것이 가능한가?Matlab에서 빈 줄을 인식하는 방법이 있습니까?
5
A
답변
2
예, 가능합니다. 매트랩 조각은 같이 보일 것입니다 :
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
2
가 여기에 하나의 가능성이다 : 지금 \ r에 ...없이
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));
+0
주석과 함께 작동합니다 :'lines = textscan (fid, '% s', 'CommentStyle', '#')' – Wok
0
나는 그가 "매트랩"라고 생각
fid = fopen('reader.m');
newline = sprintf('\n');
line = fgets(fid);
while ischar(line)
if strcmp(newline, line)
disp('Empty line');
else
disp('Non-empty line');
end
line = fgets(fid);
end
잘 작동 .. . –