How can I write an array to a txt file such that it looks like MATLAB syntax
1 次查看(过去 30 天)
显示 更早的评论
If I have an array, for example
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];
How can I write this to a text file such that when I do, it will look the same as what I wrote to declare A? In otherwords I want the txt file to contain
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];
0 个评论
采纳的回答
Fangjun Jiang
2023-4-25
use mat2str(), write the string to the text file
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];
str=mat2str(A)
eval(str)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!