How to use writetable command in a for loop

조회 수: 8 (최근 30일)
Bhaskar panchireddi
Bhaskar panchireddi 2016년 6월 2일
댓글: Voss 2023년 8월 28일
while using writetable command in a for loop i'm able to save the text file only for the last iteration value. Hoe can i save all the text files using this writetable command?

답변 (2개)

Taha
Taha 2017년 1월 11일
for m=1:10
test = [m:m+20];
T=table(test);
writetable(T,['test' num2str(m) '.txt'],'Delimiter','\t');
end
here is the solution! this code generates text files with the names: test1.txt, test2.txt.... using the for loop in MATLAB
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 8월 28일
편집: Dyuman Joshi 2023년 8월 28일
@Ellen Berry Go through the documentation of writematrix to understand the proper syntax.
If your error still persists, ask a new question specifying the problem/error you are facing.
Voss
Voss 2023년 8월 28일
@Ellen Berry: For writing an Excel file (e.g., .xlsx), omit the 'Delimiter','\t' arguments. Delimiter is for text files only.
for m=1:10
test = [m:m+20];
T=table(test);
writetable(T,['test' num2str(m) '.xlsx']);
end

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


Walter Roberson
Walter Roberson 2016년 6월 2일

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by