Cannot save a matrix into a csv file correctly
6 次查看(过去 30 天)
显示 更早的评论
So I have a matrix with doubles inside like this
0.001 9.86543...
0.002 5.26811...
0.003 4.91702...
and so on.
Using writematrix saves all column into a single column. Changing the delimiter option didn't change the result. It only changed how the numbers are separated, but they are still bunched up into a single column when I open the csv file.
How do I fix this?
2 个评论
Ramtej
2023-12-7
Hi Hayao,
Can you share how your matrix looks like? "writematrix" should work fine in your case.
Dyuman Joshi
2023-12-7
The code below works fine on my R2021a, see the attach csv file for reference.
Please share the matrix you have, with the call to writematrix() you are using to save the data in csv file.
y = reshape(magic(6), [], 2);
disp(y)
writematrix(y, 'File.csv')
回答(1 个)
Chunru
2023-12-7
A = [0.001 9.86543
0.002 5.26811
0.003 4.9170]
writematrix(A, "matrixA.txt");
type matrixA.txt
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!