Borrar filtros
Borrar filtros

Change the file-name in tblwrite when created table

1 visualización (últimos 30 días)
Ahmed
Ahmed el 26 de Ag. de 2014
Respondida: Geoff Hayes el 26 de Ag. de 2014
I want to create 15 txt tables with different names by using tblwrite in matlab. my attempt was in this code I want to create 15 txt tables with different names by using tblwrite in matlab. my attempt was in this code
for j=1:15 rownames=char(rownames1(:,j)); T(:,1)=[1:length(K_minus_t)]; table=char(T(j,1)); colnames{j}={'lambda_L';'C_L';'lambda_N';'tau_N';'lambda_c';'tau_c';}; values{j}=[coef_line lam_tau_curve lam_tau_cap]; tblwrite(values{j},colnames{j},rownames,'table.txt'); end unfortunately, it was failed. Any help would be greatly appreciated. I will be grateful to you.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 26 de Ag. de 2014
Ahmed - you don't really state what the problem is with your code, only that the attempt failed. But based on your question header, Change the file-name in tblwrite when created table, it suggests that you want a unique name for each table written to file.
The line of code that writes the table to file is
tblwrite(values{j},colnames{j},rownames,'table.txt');
where the same filename, table.txt, is used for each of the 15 iterations of the for loop. So only the data from the 15th iteration will be saved. You can replace the above code with that which will create a file name based on the iteration number
filename = sprintf('table%02d.txt',j);
tblwrite(values{j},colnames{j},row names,filename);
Now when you run the code, each of the 15 tables will be saved to their own file. The files will be named as table01.txt, table02.txt, ...,table15.txt.
Try the above and see what happens!

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by