How to update a app designer UIAxes plot in real time
248 views (last 30 days)
Show older comments
Jeffrey Klein on 15 Feb 2018
Commented: Eric Sargent on 9 Dec 2020
I'm trying to use app designer to plot data that's being acquired in real time. When I've done this type of thing in the past, I used set('Xdata') and set('Ydata') to update just the data that was being displayed without fully redrawing the plot, so the update was faster and smoother.
As far as I can figure, there's no equivalent for UIAxes. All of the examples I have found use the format plot(UIAxes, datax, datay). Are there any recommendations on how to do this?
Camile van der Heijden on 22 Feb 2018
Another thing that may or may not suit your application is using the 'animatedline' object/function. It is specifically created to improve plotting animation efficiency.
Without example code it is of course hard to provide a specific solution, but I hope this helps you. Feel free to ask clarification.
Camile van der Heijden on 27 Feb 2018
I just realized I didn't actually answer your question. You can either create a (primitive) line object in the UIAxes of your choice and update it through 'myUIAxes.XData = newXData;' and 'myUIAxes.YData = newYData;'
or using the 'set' function, as you used to do with normal figures. Another option is creating an animated line object (again in the UIAxes specified by you) and using 'addpoints' function to add new points to your graph. You could even use the 'MaximumNumPoints' property to delete old data past a certain maximum amount of data points. You also might want to look at the link at the bottom of my post.
In my case, I was using a timer set to fire about 20 times/sec and going from plot to 'lines' updated through XData and YData markedly improved performance. Just not enough unfortunately. Some pointers I got from ML support:
Animations by repeatedly setting XData, YData properties of objects suffer from efficiency issues in all settings but are more pronounced in web graphics/appdesigner settings.
Here are some issues
1) Setting new XData (and other data) effectively forces us to send data to the rendering system. With graphics in a 'figure', this meant having to load the data to the GPU every time. This is an expensive operation.
In the future we hope to build better animation API to allow efficient use of GPU for changing XData/YData situations.
Graphics performance documentation page has a lot more information related to this.
Hope this helps!
Daniel de Almeida Cardoso Soares on 22 May 2020
Edited: Daniel de Almeida Cardoso Soares on 8 Jun 2020
In my case, I have solved this problem adding the function drawnow.
Every time this function runs, all of the graphics/tables are updated.
This may work in this given instance, but I wouldn't recommend using drawnow as a general solution to this. Please see the anwer below about using a timer as a more robust solution.
You can also try using a timer to plot the data at a given interval.
An example can be found here:
Find more on Develop Apps Using App Designer 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!