plotting graph involving converting time intervals

1 次查看(过去 30 天)
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