How to convert time format to plot a .csv file?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2016년 6월 5일
[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
참고 항목
카테고리
Help Center 및 File Exchange에서 Classical Control Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!