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!