필터 지우기
필터 지우기

how to write text files in a specific format?

조회 수: 13 (최근 30일)
Hydro
Hydro 2017년 10월 18일
편집: KL 2017년 10월 19일
Hello, Below is my code that would write data into a text file.
fileID = fopen('G:\FLOW_OUT_32.txt','w');
formatSpec = '%d %2.5f \n';
[nrows,ncols] = size(output32);
for row = 1:nrows
fprintf(fileID,formatSpec,output32{row,:});
end
fclose(fileID);
I would like the data to be written in the format shown below. Any help would be appreciated. Thanks
1
3 2.867000e-001
4 3.328000e-001
5 1.607000e-001
6 8.805000e-001
7 1.124000e+000
8 6.947000e-001
  댓글 수: 1
Hydro
Hydro 2017년 10월 18일
Sorry. i just replace f with e and it workded. just in case anyone else needs it.

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

답변 (1개)

KL
KL 2017년 10월 19일
편집: KL 2017년 10월 19일
You shouldn't need a loop.
fileID = fopen('G:\FLOW_OUT_32.txt','w');
fprintf(fileID,'%d %12.6e\n',output32.'); %assuming out32 is a nx2 matrix
fclose(fileID);

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by