csvwrite is storing wrong number

조회 수: 8 (최근 30일)
Abolfazl Taghribi
Abolfazl Taghribi 2019년 1월 25일
편집: dpb 2019년 1월 28일
I'm using "csvwrite" command for storing a 2d matrix with size 104937*1810. Is there any limitation on this command or csv file? The produced file is 670 MB but in each stored row there are exactly 5 numbers which are not the same as matrix in the matlab. All numbers are int32 and the wrong numbers are in different colomns in each row.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 25일
Would it be possible to xlswrite() or writetable() to a .xlsx file and attach that for us to test with?
Also which release are you using?

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

채택된 답변

dpb
dpb 2019년 1월 26일
편집: dpb 2019년 1월 26일
>> tstary=int32(randi(2^31,104937,1810));
>> whos tstary
Name Size Bytes Class Attributes
tstary 104937x1810 759743880 int32
>> tstary(1:3,1:5)
ans =
3×10 int32 matrix
1186639717 717774140 2035668545 471416973 522550194
2056308186 151423171 131112521 1937130594 1414722413
1917344954 1185569608 203068410 614639920 243357862
>> csvwrite('tstary.csv',tstary)
Content of tstary.csv from file viewer...
1.1866e+09,7.1777e+08,2.0357e+09,4.7142e+08,5.2255e+08,1.1246e+09,1.5343e+09,3.2607e+08, ...
2.0563e+09,1.5142e+08,1.3111e+08,1.9371e+09,1.4147e+09,7.5605e+08,7.9947e+08,6.188e+08, ...
1.9173e+09,1.1856e+09,2.0307e+08,6.1464e+08,2.4336e+08,9.5385e+08,1.0362e+09,2.0352e+09, ...
...
The content is exactly what the documentaion for csvwrite says it will be--the data in %g format with a maximum of 5 digits of precision.
The help there indicates to use dlmwrite with optional precision argument, but for such a large file, using a text format is absurd way to store/move/transport data. Use stream or some other form instead.
But, csvread is working as expected.
  댓글 수: 3
dpb
dpb 2019년 1월 26일
편집: dpb 2019년 1월 28일
I misunderstood initially, too, I think, but decided that probably it was a case of the symptom not being recognized as to cause that produced a mistaken interpretation of the cause of the difference and that led to asking the wrong question--or wording the question to be about the wrong problem.
Abolfazl Taghribi
Abolfazl Taghribi 2019년 1월 27일
편집: Abolfazl Taghribi 2019년 1월 27일
I did not mention the "maximum of 5 digits of precision" limitation for csvwrite before. This was the problem. I should use dlmwrite instead. Thanks dpl .

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by