.txt ( and not the automatic.mat) using save with num2str option

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.

 Réponse acceptée

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 .

2 commentaires

thanks! this works like a charm!
and of course nelettrodi<=10

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Licensing on Cloud Platforms dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by