Effacer les filtres
Effacer les filtres

How to save a matrix output to a text file that located in different folder?

18 vues (au cours des 30 derniers jours)
Hello All,
I want to save a matrix output (My_matrix ) to a text file (scaled_1.txt) that located in different folder than the script (.m file).
I have tried
fid = fopen('F:\output\scale\scaled_1.txt', 'w');
fprintf(fid, '%s\n', ' My_matrix ');
fclose(fid)
This will only print the text (My_matrix ) and not the content of the matrix.
I appreciate your suggestions in advance
Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Sep 2017
filename = 'F:\output\scale\scaled_1.txt';
arrayname = 'My_matrix';
fid = fopen(filename, 'w');
fprintf(fid, ' %s \n', arrayname);
fclose(fid)
save(filename, arrayname, '-ascii', '-double', '-append');
  2 commentaires
Abdulaziz Abutunis
Abdulaziz Abutunis le 16 Sep 2017
Thank you Walter for the great suggestion as usual. BUT!! The code you suggested was able to write the matrix to the specified text file but it also writes the matrix name (My_matrix) to the text file at the beginning. Do you have any further adjustment to prevent printing the matrix name to the text file and only keep matrix content.
Thank you,
Abdulaziz Abutunis
Abdulaziz Abutunis le 16 Sep 2017
I have removed this line fprintf(fid, ' %s \n', arrayname); which responsible for the typing the string, and it works great Thanks again

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by