plotting graph involving converting time intervals
1 view (last 30 days)
Show older comments
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 Comments
Mathieu NOE
on 3 Mar 2022
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
on 4 Mar 2022
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.
Answers (1)
Abhishek Chakram
on 16 Nov 2023
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:
- datetick: https://www.mathworks.com/help/matlab/ref/datetick.html
- plot: https://www.mathworks.com/help/matlab/ref/plot.html
Best Regards,
Abhishek Chakram
1 Comment
Peter Perkins
on 16 Nov 2023
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.
See Also
Categories
Find more on Discrete Data Plots 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!