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 Center および File ExchangeSpreadsheets についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by