MATLAB Answers

Tony

Help with parsing a csv

Asked by Tony
on 28 Mar 2013

Hi,

I'm a fairly new user to MATLAB and programming. I need some help and guidance with the following problem.

I have a lot of csv files with only 1 line of data in each. The data in each csv looks like the following: 39605.000000,39605.333433,39605.333433,8.000000,0.000000,3.441000,4.239000,4.754000,5.179000

The first 5 columns looks like it is date/time related and the last 4 columns are the data values I need.

I am trying to create 4 new csv's from the 4 data values with the following format: 'yyyy.mm.dd.HH:MM:SS', data

Can anyone please help or provide me some guidance on how to get this accomplished? I've only been able to read the csv and get the data with fopen. I'm not sure how to change create the date format I need from the file.

  9 Comments

Tony
on 28 Mar 2013

I got it to work with CSVREAD, I'm trying to create a new csv with the following method. Except instead of showing a 0 in the last like the code is trying to do, its showing 48... I have no idea where that is coming from

 dataLine = csvread(([archiveDir list1(j).name]));
    fid = fopen('temp.csv', 'w');
    fprintf(fid,'%s,%6.8f,%6.8f,%6.8f,%6.8f,%d\n', datestr(x2mdate(dataLine(2)),'yyyy.mm.dd.HH:MM:SS'),dataLine(6),dataLine(6),dataLine(6),dataLine(6),'0');
    fclose(fid);
Tony
on 28 Mar 2013

This is the output:

2008.06.06.08:00:08,3.44100000,3.44100000,3.44100000,3.44100000,48

per isakson
on 28 Mar 2013

Hint:

    >> double('0')
    ans =
        48
    >> 

Products

No products are associated with this question.

0 Answers

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today