plotting graph involving converting time intervals

조회 수: 1 (최근 30일)
Max Fairhurst
Max Fairhurst 2022년 3월 3일
댓글: Peter Perkins 2023년 11월 16일
I have a large number of time values that start at a large number of milliseconds and increase with equal interval, along with an equal amount of speeds. I am looking to plot a graph with the x axis having the time values with interval of one day and starting at day 1 and the y axis having an equal amount of plots for speed. Any ideas?
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2022년 3월 3일
hello
sounds to me like you want to pick only data at one day interval from your milliseconds sampled data
this can be simply achieved by interpolation using interp1
Peter Perkins
Peter Perkins 2022년 3월 4일
Max, your description is not very clear. You need to give a short clear example of what you have and what you want the plot to look like.

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

답변 (1개)

Abhishek Chakram
Abhishek Chakram 2023년 11월 16일
Hi Max Fairhurst,
It appears to me that you want to plot milliseconds with equal interval of a day, along with an equal amount of speeds. For this, you can use the “plot” and “datetick” functions. Here is an example for the same:
% Convert time values from milliseconds to serial date numbers
t = t / (24 * 60 * 60 * 1000); % divide by the number of milliseconds in a day
t = t + datenum (0); % add the serial date number for January 0, 0000
% Plot speed values against date numbers
plot (t, s)
xlabel ('Time (days)')
ylabel ('Speed')
% Format x-axis tick labels as days
datetick ('x', 'keeplimits', 'keepticks')
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram
  댓글 수: 1
Peter Perkins
Peter Perkins 2023년 11월 16일
datenum and datetick are no longer the recommended way to make plots vs. time.
The fact that you had to do this
t = t + datenum (0); % add the serial date number for January 0, 0000
should suggest that there's a better way. That way is to use durations.

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

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by