필터 지우기
필터 지우기

Cannot save a matrix into a csv file correctly

조회 수: 5 (최근 30일)
Hayao
Hayao 2023년 12월 7일
답변: Chunru 2023년 12월 7일
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
Ramtej 2023년 12월 7일
Hi Hayao,
Can you share how your matrix looks like? "writematrix" should work fine in your case.
Dyuman Joshi
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)
35 26 3 21 31 22 8 17 30 12 4 13 1 19 32 23 9 27 28 10 5 14 36 18 6 24 7 25 2 20 33 15 34 16 29 11
writematrix(y, 'File.csv')

댓글을 달려면 로그인하십시오.

답변 (1개)

Chunru
Chunru 2023년 12월 7일
A = [0.001 9.86543
0.002 5.26811
0.003 4.9170]
A = 3×2
0.0010 9.8654 0.0020 5.2681 0.0030 4.9170
writematrix(A, "matrixA.txt");
type matrixA.txt
0.001,9.86543 0.002,5.26811 0.003,4.917

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by