xlswrite precision problem

조회 수: 2 (최근 30일)
Rok mr
Rok mr 2012년 2월 17일
Hi!
I have a huge amount of data in array (60000x17) with precision of 3 decimal places. After some operations I would like to save that array in excel file by using xlswrite command. The problem is that whenever I do that the excel file become where huge because all the numbers are stored as double (15 decimal places).
So my question is how can you store an array with only 3 decimal places by using xlswrite command?
I also tried to transform numbers into single before saving but it didn't work.
thank you in advance!

채택된 답변

Ken Atwell
Ken Atwell 2012년 2월 17일
xlswrite does not provide this option itself.
You could do the rounding in MATLAB before committing to file:
A=rand(3)
xlswrite('foo.xlsx', round(A*1e3)/1e3);
This should mostly work, but I suppose there may be cases where an exported value can be ?.???99999999999999 or some such. There may be a better numerical way to do this kind of round, but I don't know what it might be.

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 2월 17일
That's only 1,020,000 elements. Hardly huge at all. Even with double precision (8 bytes per number), your file is only about 8 megabytes, right? That's not even as big as a run of the mill point and shoot camera image. Why do you need to make this tiny file even smaller? What kind of file sizes are you getting from Excel?
  댓글 수: 1
Rok mr
Rok mr 2012년 2월 18일
the problem was that I used xslwrite('hhh.xls',...) and not a newer extension of excel .xlsx.
In first case if I tried to merge 5 arrays (60000x17) on a separate sheets in one file it was 100MB. But if I use .xlsx the file is 40MB and it's okay.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by