How to save data from a for loop?

조회 수: 4 (최근 30일)
Niya Bedzheva
Niya Bedzheva 2019년 9월 2일
답변: Stephen23 2019년 9월 2일
Hello everyone ,
i will need your help. I am running a consequence of files with a for loop, which matlab is reading and making some calculations with their data. What i want to do is to save certain results from the calculations of every file that is running (from every file thas is going through the loop). I need to do that in xlsx or txt file. Thank you in advance!
p.s i managed to succeed in saving the graphics from every file that i plotted:
savefig (h1, sprintf('Experimental_drying_rates_%s.fig ', num2str(i)));
savefig (h2, sprintf('Evaporation_coefficent_beta_%s.fig ', num2str(i)));
savefig (h3, sprintf('Calculated_drying_rates_%s.fig ', num2str(i)));
  댓글 수: 5
Stephen23
Stephen23 2019년 9월 2일
편집: Stephen23 2019년 9월 2일
writetable is not sprintf. Do not mix them up.
To generate the filename, use sprintf as I showed you:
F = sprintf('Results_%d.txt',i);
Then use that filename in writetable:
writetable(R,F)
Niya Bedzheva
Niya Bedzheva 2019년 9월 2일
Thank you very much, it worked! i just don't know how to accept your answer :/

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

채택된 답변

Stephen23
Stephen23 2019년 9월 2일
Where T is your table:
for k = ...
T = your table
F = sprintf('Results_%d.txt',k);
writetable(T,F)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by