2010-06-16 3 views

답변

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 
+3

잘 작동 .. . –

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