problem in fprintf
이전 댓글 표시
hi,
In the following code ,at first I opened file for reading in order to replace '|' with ','.
Then I opened another file for writing the the above data. Each time the number of ',' equal 23 , the writing of data in file will be in new line.
But, the resulting file just one line .
%%%%%%%%%%%%%%%%%%%%%
the code:
f=fopen('u2.txt','r');%%%%%%open the original data file
b=fscanf(f,'%s');
for i=1:length(b)
if b(i)=='|'
b(i)=',';
end
end
k=0;
f1=fopen('u4.txt','w+');
for j=1:length(b)
fprintf(f1,'%s',b(j));
if b(j)==','
k=k+1;
end
if k==23
k=0;
fprintf(f1,'%s','\n');
end
end
%%%%%%%%%%%%%%%%%
thanks
답변 (1개)
Walter Roberson
2011년 9월 13일
0 개 추천
Either use just about any other editor than the one you are using to view the file, or else use 'wt+' instead of 'w+' when you open the output file.
Note: you should really only use 'w+' or 'wt+' if you are going to be using fseek() to move around in the output file while it is still open. If all you need to do is write the file, then please use 'w' for binary files and 'wt' for text files.
카테고리
도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!