How to use writetable command in a for loop

5 Ansichten (letzte 30 Tage)
Bhaskar panchireddi
Bhaskar panchireddi am 2 Jun. 2016
Kommentiert: Voss am 28 Aug. 2023
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?

Antworten (2)

Taha
Taha am 11 Jan. 2017
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 28 Aug. 2023
Bearbeitet: Dyuman Joshi am 28 Aug. 2023
@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 am 28 Aug. 2023
@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

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 2 Jun. 2016

Kategorien

Mehr zu Standard File Formats finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by