Change the file-name in tblwrite when created table
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Geoff Hayes
on 26 Aug 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!
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!