How to save table in workspace as txt/.m file in matlab ?
9 次查看(过去 30 天)
显示 更早的评论
Hi,
Table is a variable containing 99*1 double values saved in workspace. I need to convert it into txt/.m file
0 个评论
回答(1 个)
Kirby Fears
2016-5-23
编辑:Kirby Fears
2016-5-23
You can use writetable to write to a text file.
writetable(data,'outputfile.txt');
If you really need this to be a .m file, you can make a new copy as .m and delete the original file.
copyfile('outputfile.txt','outputfile.m');
delete('outputfile.txt');
2 个评论
Kirby Fears
2017-1-5
编辑:Kirby Fears
2017-1-5
Abhishek,
In that case, what you have is a double array instead of a table (in Matlab parlance).
You can simply use csvwrite. Here's an example.
csvwrite('outputfile.txt',magic(10));
If you want the result to be .m format, just indicate the file name accordingly:
csvwrite('outputfile.m',magic(10));
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!