Cannot create .txt file in Matlab online
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to create a .txt to put some in some numbers to pull back out later.
My code is:
fileID = fopen('MyFile.txt', 'w');
When I run the code it creates a varable fileID that is shown in the workspace panel (on the lower left of the screen) as a double. But no file is created over in the files panel and when I try to read from that file it then gives an error that the file doesn't exist.
0 commentaires
Réponses (1)
Star Strider
le 24 Sep 2023
Modifié(e) : Star Strider
le 25 Sep 2023
I am not certain what the problem is. Using fopen only creates the file ID, as you discovewred.
To write the file, you need to do something like this —
fileID = fopen('MyFile.txt', 'w');
A = magic(5)
fprintf(fileID, '%2d %2d %2d %2d %2d\n', A);
fclose(fileID);
type('MyFile.txt')
That should work as well on MATLAB Online.
EDIT — (25 Sep 2023 at 15:18)
Exporting it to your computer requires that you go to MATLAB Drive, check the file name, and then click on ‘Download’. (Added in EDIT.)
.
4 commentaires
Star Strider
le 27 Sep 2023
Did you try your fprintf calls with my code (using them instead of my fprintf call)?
Can you try them here? (Use the Code button ‘Insert a line of code’ to format it as code and then run the code by clicking on the green Run arrow in the top toolstrip.)
I have never had any problems with MATLAB Online (that I did not cause myself).
Voir également
Catégories
En savoir plus sur Low-Level File I/O dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!