Why can not the 'save' command store a matrix of single precision into a txt file? Warning: Attempt to write an unsupported data type to an ASCII file. Variable 'AA2' not wri
4 views (last 30 days)
Show older comments
Below is the piece of my code:
save nedata-3.3new.txt AA1 -ascii;
AA2=single(AA1);
save nedata-3.3new.txt AA2 -ascii;
'AA1' is a 2D matrix of double precision and it can be dumped successfully. But if I convert 'AA1' into the single precison matrix, 'AA2', the warning and error appear. What's the reason and how can I settle this problem? Thank you ahead of time.
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'AA2' not written to file.
0 Comments
Accepted Answer
Stephen23
on 5 Jul 2023
Edited: Stephen23
on 5 Jul 2023
" What's the reason..."
Because venerable SAVE does not really offer much functionality when exporting to text file, due to it being really just a left-over from a long long time ago when MATLAB only had one data type and did not have more functions for import and export. SAVE has no options when saving to textfile and limited functionality, just like it did many years ago.... because it is the wrong tool for the job.
"...how can I settle this problem?"
Avoid using SAVE to export to text file.
Prefer using one of the tools that is specifically for exporting to text files e.g. WRITEMATRIX:
M = rand(3,5,'single');
writematrix(M,'test.txt')
You can find a list of the functions for importing/exporting to textfile here:
Note that SAVE is not one of them.
More Answers (0)
See Also
Categories
Find more on LaTeX 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!