.txt ( and not the automatic.mat) using save with num2str option
2 views (last 30 days)
Show older comments
Hi all, I have this code:
for l=1:nelettrodi
for j=l+1:nelettrodi
for k=j+1:nelettrodi
V_ = V_I(l)+V_I(j)+V_I(k);
save(['V_', num2str(l), num2str(j),num2str(k)],'V_')
My problem is that this save the variable V_ in a .mat file, but I want it to be a .txt. I tried this:
save(['V_', num2str(l), num2str(j),num2str(k)]'.txt','V_')
and it seems like it does the jobs. I say it seems since it saves it as a .txt file but the content of this file is just some line with strange symbols. I need a .txt file because another program has to use this variable and can read only .txt. Thank you very much for your time, Giorgio.
0 Comments
Accepted Answer
Walter Roberson
on 23 Jul 2012
You need to add '-ascii' as a final parameter. Also you can make your code cleaner:
filename = sprintf('V_%d%d%d.txt' l, j, k);
save(filename, 'V_', '-ascii')
Note: if l, j, or k can exceed 10, then you can generate ambiguous file names with what you are doing now. For example, j=1, k=12 cannot be told apart from j=11, k=2 .
More Answers (0)
See Also
Categories
Find more on Licensing on Cloud Platforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!