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
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
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
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:
- 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 件のコメント
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 Center および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!