I am trying to plot a .csv file.
When I plot X i get the figure that i want but when I plot X against time, I get figure 2. Any ideas why this is happening?

 채택된 답변

Clayton Gotberg
Clayton Gotberg 2021년 4월 17일
편집: Clayton Gotberg 2021년 4월 17일

0 개 추천

In the attached CSV, the time data is the same for every 100 columns or so. Because of this, MATLAB is plotting all of the events that happened at that time at the same position on the x-axis. You will not be able to use the time information in the csv for plotting because the time is only measured to the second but you are taking measurements hundreds of times per second.
If you want to plot vs. time, you will need to create a new time vector.
time_new = linspace(start_time,end_time,size(X,1));
%start_time is the earliest time in the sequence
will create equally spaced points in time to plot X against. Note that if you started or stopped measuring in the middle of a second, the points will not match up with the true time exactly if you start or stop from the recorded value:
true_time = [0.5 0.75 1 1.25 1.5 1.75 2 2.25];
time_new = [0 0.2857 0.5714 0.8571 1.1429 1.4286 1.7143 2];
If the data samples you took are not equally spaced in time, you will need to re-measure your data with a more accurate clock.

댓글 수: 4

I'm sorry, I should have clarified that start_time and end_time would need to be defined by you before you ran this command.
start_time = % The earliest time for which you have data
end_time = % The time you stopped taking measurements
That is because '14:44:47' and '14:44:59' are characters, not scalars. You need to choose or determine scalars that fit the interval.
For example,
time_new = linspace(47,59,size(X,1));
should work and you can translate beetween one of the resulting values - say 53.75 - as meaning '14:44:53.75'.
If when you plot the resulting data you want the time to show up as a label on the X-axis, look at the XTickLabels command. @Star Strider's answer about labelling charts with characters should be a great start.
start_time = duration(14,44,47);
end_time = duration(14,44,59);
time_new = linspace(start_time, end_time, size(X,1));
Ancalagon8
Ancalagon8 2021년 4월 17일
Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2021년 4월 17일

편집:

2025년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by