Cannot create .txt file in Matlab online
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2023-9-24
编辑:Star Strider
2023-9-25
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 个评论
Star Strider
2023-9-27
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).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!