plotting graph involving converting time intervals
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Mathieu NOE
el 3 de Mzo. de 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
el 4 de Mzo. de 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.
Respuestas (1)
Abhishek Chakram
el 16 de Nov. de 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 comentario
Peter Perkins
el 16 de Nov. de 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.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!