필터 지우기
필터 지우기

Using a function strncmp

조회 수: 1 (최근 30일)
MIHYUN
MIHYUN 2014년 1월 16일
댓글: MIHYUN 2014년 1월 22일
I have a Text file.
And I want to ignore if the first character of the line begins with #.
Also if it begins without # , I want to output.
The code I wrote is as follows .
fid=fopen('asdf1.txt', 'r');
tline=fgetl(fid);
while ischar(tline)
if strncmp(tline,'#',1);%%this part is problem.
Please tell me what to do.
Thank in advance.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 16일
편집: Azzi Abdelmalek 2014년 1월 16일
out=[];
fid=fopen('asdf1.txt');
tline=fgetl(fid);
while ischar(tline)
if ~strncmp(tline,'#',1);
out{end+1}=tline;
end
tline=fgetl(fid);
end
fclose(fid)
But you can just compare them with
if tline(1)=='#"
  댓글 수: 1
MIHYUN
MIHYUN 2014년 1월 22일
Thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by