MATLAB Answers

Reading CSV file with time stamped data and Plotting data with Time in the X-axis

59 views (last 30 days)
Fortunate Musengi
Fortunate Musengi on 10 Jan 2017
Answered: Peter Perkins on 12 Jan 2017
I have a csv file with data imported from a PLC time stamped to msec. I wanted to use the following "csvread" command to read the data and plot the data with time on the x axis.
Time Data format 12:38:06;865 (HH:MM:SS;FFFF) See attached csv file
Can you please assist me to be able read the timestamp in Matlab and plot the data

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 10 Jan 2017
[num,txt,raw] = xlsread('Test1.csv');
time = vertcat(txt{2:end,1}) ;
gvpos = num(:,1) ;
vlvlimcm = num(:,2) ;
speedctrl = num(:,3) ;
speed = num(:,4) ;
pidout = num(:,5) ;
%
dn=datenum(time,'HH:MM:SS;FFF');
plot(dn,gvpos)
datetick('x','keepticks','keeplimits')

  1 Comment

Fortunate Musengi
Fortunate Musengi on 11 Jan 2017
Thanks a lot, that's exactly what I was after. Is there a way to display time as HH:MM:SS.FFFF when using a cursor on the graph.

Sign in to comment.

More Answers (1)

Peter Perkins
Peter Perkins on 12 Jan 2017
I'm not familiar with PLC files, but in anything like a recent MATLAB, you should be able to use readtable and datetime. Something like
t = readtable('Test1.csv','Format','%{HH:mm:ss;SSS}D,%f%f%f%f')
Not sure if the file has column headers, you may need to adjust the table's variable names. It looks like you'll want to convert the datetime to a duration, because it would have been read in with the date portion set to "today". Something like
t.Time = t.Time - datetime('today');
t.Time.Format = 'hh:mm:ss.SSS'
should do that. Then plot as
plot(t.Time,t.GVPos)
Hope this helps.

  0 Comments

Sign in to comment.