我有一个while循环,它会执行但会无限期地运行。我不确定会导致这种情况发生的原因。任何帮助将不胜感激。
Fid=fopen('plaintext.txt');
str= fgetl(Fid);
count=0;, count1=0;, count2= 0;, count3=0;
while ischar(str);
if regexp(str, '\w+');
count= count + 1;
end
count1=count1+length(str);
if regexp(str, 'I');
count2= count2 + 1;
end
if regexp(str, 'the');
count3= count3 + 1;
end
if regexp(str, '#');
count4= count4 + 1;
end
end
答案 0 :(得分:0)
将fgetl
功能移至while
循环:
Fid=fopen('plaintext.txt');
count=0;, count1=0;, count2= 0;, count3=0; count4=0;
while 1
str= fgetl(Fid);
if ~ischar(str);
break;
end
if regexp(str, '\w+');
count= count + 1;
end
count1=count1+length(str);
if regexp(str, 'I');
count2= count2 + 1;
end
if regexp(str, 'the');
count3= count3 + 1;
end
if regexp(str, '#');
count4= count4 + 1;
end
end