Save serial datenum as decimal, not scientific notation

조회 수: 8 (최근 30일)
Anke Kügler
Anke Kügler 2019년 9월 26일
댓글: James Tursa 2019년 9월 26일
Hello,
I'm reading in a csv file containing timestamps as serial numbers. After some computation, I need to save the array back as a csv file. However, when importing, Matlab converts the decimal datenums into scientific format, i.e. 737389.4167 becomes 7.3739e+05 and they're stored in that format. I know this is the case because when I subsequently import the data in Excel, the format is different between original and edited file. This causes problems when importing the files into
I tried to work around it by converting it in str and cells, but that creates other problems when saving as csv.
Matlab R2018a
[file,path] = uigetfile('*.csv');
fn = fullfile(path,file);
A = csvread(fn);
[filepath,filename,ext] = fileparts(fn);
fnout=fullfile(path,strcat(filename,'_edited',ext));
csvwrite(fnout,A)
Any help is really appreciated as this has created a lot of headaches.
  댓글 수: 2
Star Strider
Star Strider 2019년 9월 26일
Please share the original file and the code you are using to read it and write write the new file. Also, what MATLAB version/release are you using?
Anke Kügler
Anke Kügler 2019년 9월 26일
edited above. I cannot share any of the data.

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

채택된 답변

Anke Kügler
Anke Kügler 2019년 9월 26일
Ok, dlmwrite instead of csvwrite seemed to fix it. So here's what I'm using instead, now:
[file,path] = uigetfile('*.csv');
fn = fullfile(path,file);
A = csvread(fn);
[filepath,filename,ext] = fileparts(fn);
fnout=fullfile(path,strcat(filename,'_edited',ext));
dlmwrite(fnout,A,'precision',15)

추가 답변 (1개)

James Tursa
James Tursa 2019년 9월 26일
편집: James Tursa 2019년 9월 26일
First, MATLAB stores all doubles the same way ... as IEEE binary floating point format. What you are seeing as "737389.4167 becomes 7.3739e+05" is simply a display issue. The underlying format for both is still IEEE binary floating point. E.g.,
>> x = 737389.4167
x =
7.3739e+05
>> format long
>> x
x =
7.373894166999999e+05
>> format short
>> x
x =
7.3739e+05
As far as your writing to csv being different from what you read in, you need to show us a sample of the csv file and also the code you are using for reading and writing. Then we can help you.
  댓글 수: 2
Anke Kügler
Anke Kügler 2019년 9월 26일
편집: Anke Kügler 2019년 9월 26일
I understand that and that's what I kept reading everywhere, yet, the problem persists. I've edited my post to include the code, but I cannot share any data. Let me try to reproduce a sample csv file.

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

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by