How to convert time format to plot a .csv file?
5 views (last 30 days)
Show older comments
Hello everyone,
I am an Electronic Engineer. I'm currently working on a project in which I need to tune a PID controller and I want to plot a generated .csv file in MATLAB to do it. The SIMATIC software has a curve recorder that I could use to do it, but it is really small in size and I would like to have much more precision; also, it would be very valuable for me to learn how to do this here in MATLAB.
I have used MATLAB in a basic level and I am currently reading about the instructions I need to do this plot, but I am posting this question here to see if you can give me some pointers in avdance. What I have already seen is that it can't plot the time in the format hh:mm:ss with "real" values on the other axis, so I need to convert the time to—I think—serial date number or some other format. I've seen the instructions to do this, but the thing is that I have a lot of values in the .csv file and haven't found how to select, dissect or separate them to do the conversion of all of them. I am attaching a screenshot of the file opened in Excel. I only need to plot the time in the x-axis and the Manipulated Variable and the Process Variable in the y-axis; I have done basic plots, but for this one I need a bit of specialized, focused help.

Thanks in advance.
0 Comments
Answers (1)
Walter Roberson
on 5 Jun 2016
[num, txt] = xlsread('Yourfile.csv');
datetimes = strjoin(txt(11:end,1), {' '}, txt(11:end,2));
time_num = datenum(datetimes);
c1 = num(1:end,1);
plot(time_num, c1)
datetick('x', 'mm:ss')
If you have R2014b or later then I recommend that you use datetime objects instead of serial date numbers:
[num, txt] = xlsread('Yourfile.csv');
datetimes = strjoin(txt(11:end,1), {' '}, txt(11:end,2));
time_obj = datetime(datetimes, 'Format', 'mm:ss');
c1 = num(1:end,1);
plot(time_obj, c1)
1 Comment
See Also
Categories
Find more on Classical Control Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!