File name as value of a variable
조회 수: 111 (최근 30일)
이전 댓글 표시
Would you please guide me how to write Excel files whose names are value of a variable, e.g. testdata_i where i is a variable?
This is the code I have that needs some adjustments. Data is a matrix whose values is decided in another loop.
for i = 1:5
filename = sprintf('%s_%d','testdata',i)
writematrix(Data,'filename.xlsx')
end
댓글 수: 0
채택된 답변
Adam Danz
2019년 6월 24일
편집: Adam Danz
2019년 6월 24일
You were really close. You just forgot to use the filename variable.
for i=1:5
filename = sprintf('testdata_%d.xlsx',i);
writematrix(Data,filename)
end
d = 'C:\Users\name\Documents\MATLAB';
for i=1:5
filename = sprintf('testdata_%d.xlsx',i);
writematrix(Data,fullfile(d,filename))
end
댓글 수: 2
madhan ravi
2019년 6월 24일
+1, SHAWN this answer , answered your question already. Had the same thing in mind but messsed up my answer.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!