using fprintf for matrix csv file

조회 수: 13 (최근 30일)
Isha Sharma
Isha Sharma 2018년 4월 10일
답변: Voss 2023년 12월 26일
I have a matrix A with size 96x16. I am running hundreds of iterations and I want to save A for each iteration. Could someone please help me how I can do this using fprintf() in Matlab.
fid = fopen('Results.csv','wt');
for k=1:1:100
A= (some equation);
fprintf(fid, '%12.6f', A);
fprintf(fid, '\n');
end
fclose(fid)

답변 (1개)

Voss
Voss 2023년 12월 26일
fid = fopen('Results.csv','wt');
ncol = 16;
format_str = [repmat('%12.6f,',1,ncol) '\n'];
for k = 1:100
A = (some equation);
fprintf(fid, 'Iteration %d\n', k);
fprintf(fid, format_str, A.');
fprintf(fid, '\n');
end
fclose(fid);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by