How to use writetable command in a for loop

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?

Respuestas (2)

Taha
Taha el 11 de En. de 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 comentarios

Ellen Berry
Ellen Berry el 28 de Ag. de 2023
Do you know how to adjust this to export as an excel file? I'm getting an error saying the delimiter is an invalid parameter
Dyuman Joshi
Dyuman Joshi el 28 de Ag. de 2023
Editada: Dyuman Joshi el 28 de Ag. de 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.
@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

Iniciar sesión para comentar.

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 2 de Jun. de 2016

Comentada:

el 28 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by