필터 지우기
필터 지우기

How to save the output of each loop in .csv file?

조회 수: 32 (최근 30일)
Noor Fatima
Noor Fatima 2022년 12월 7일
댓글: Voss 2022년 12월 7일
for i = 1:20
output = myfunction(a, b, c);
Result(:,i) = output;
writematrix(output, 'Output_i.csv')
end
The 'Result' save the output as 100 rows and 20 columns,
I want to save each column of Result in a seperate .csv file. i.e., I need 20 .csv files
I have tried the following
for i = 1:20
output = Result(:,i)
writematrix(output, 'Output_i.csv')
end
Is there any way either with in the loop or after obtaing result for each loop to save the oputput of each iteration of loop?
Thanks

채택된 답변

Voss
Voss 2022년 12월 7일
writematrix(output, sprintf('Output_%d.csv',i))
  댓글 수: 2
Noor Fatima
Noor Fatima 2022년 12월 7일
@Voss Thanks a lot.
Voss
Voss 2022년 12월 7일
You're welcome!

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

추가 답변 (1개)

Arif Hoq
Arif Hoq 2022년 12월 7일
if your "result " is in matrix form, then try this
result=randi(100,100,20);
% making text files
for j=1:size(result,2)
col= result(:,j);
writematrix(col,[num2str(j) '.txt'])
end

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by