How to add a datetime array to addpoints for an animated line plot?
显示 更早的评论
Hi,
Let's say I have a datetime & temperature arrays as following:
Xdata Ydata
'05:00:00.048' 41
'05:00:00.052' 42
'05:00:00.056' 40.5
'05:00:00.060' 43
'05:00:00.064' 44
'05:00:00.068' 45
'05:00:00.072' 45.5
'05:00:00.076' 46
'05:00:00.080' 47
'05:00:00.084' 47.5
'05:00:00.088' 48
I would like to plot an animation line using addpoints. "addpoints" needs Xdata to be a double but I need to plot it as a datetime object.
Help me understand if there's another way around this.
Thanks,
Sun
采纳的回答
更多回答(2 个)
Ajay Kumar
2019-10-2
1 个投票
Try this:
Convert the datetime values to numbers using datenum.
Fetch these datenum values as x parameter to addpoints.
While plotting convert these datenum values to datetime again using datetime and 'ConvertFrom'.
I hope it works.
1 个评论
Sun
2019-10-2
编辑:Walter Roberson
2019-10-2
Noah Prisament
2023-6-7
The "animatedline" now supports all numeric datatypes as well as datetimes and durations for all axes as of R2023a!
In order to plot your data on an "animatedline" you can now utilize the following example:
h = animatedline(NaT, NaN);
addpoints(h, Xdata, Ydata);
or to initialize the "animatedline" with data:
h = animatedline(Xdata, Ydata);
2 个评论
unknown
2025-1-3
How to use animatedline to draw figure with datetime in app designer UiAxes ?
An occurs error when use addpoints .
app.aline=animatedline(app.UIAxes,app.data.time,app.data.(app.figname));
addpoints(app.aline,datetime(app.data.time(end),'Format','yyyy-MM-dd HH:mm:ss'),app.data.(app.figname)(end))
Matlab version is R2024b
Noah Prisament
2025-1-3
Hi, what is the error that you are experiencing, can you send the full error text in a reply?
A potential issue is if your current axes already has non-datetime data on the x-axis. A given axes can only have either numeric or non-numeric data on either axis.
类别
在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!