Can any one help me in adding new line space to the result. Thanks in advance
4 次查看(过去 30 天)
显示 更早的评论
fid=fopen('largeadd.m','r');
result=' ';
while(feof(fid)~=1)
temp=char(fread(fid));
for i=1:max(size(temp))
if(~isspace(temp(i,1)))
result=strcat(result,char(temp(i,1)));
disp(isspace(temp(i,1)));
else
result=strcat(result,'\n');
end
end
end
end
disp(result);
0 个评论
回答(2 个)
Walter Roberson
2014-2-5
result = strcat(result,sprintf('\n'));
2 个评论
Walter Roberson
2014-2-6
fread(fid) reads the entire file.
max(size(temp)) can be replaced by length(temp)
I have to wonder why you are doing all of this. Why not just read the file and then use
temp(isspace(temp)) = sprintf('\n');
Image Analyst
2014-2-6
Why do all that? Just use fgetl() or fgets().
thisLine = fgets(fid);
lineWithExtraLineFeed = sprintf('%s\n', thisLine);
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!