using fprintf for matrix csv file

19 次查看(过去 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