How to update 3D plot in real time with slider?

16 views (last 30 days)
I have an app that plots a 3D cube and black axis line. I plotted my cube and line as patches using the "fill3" function, and I turned on "rotate3D" to allow the plot to be freely rotated with the mouse. I also created a slider that adjusts the length of the black line. In the slider callback, I recall the "fill3" function with, in addition to the original unchanged data, the new data for the resized black line.
The issue is that when I adjust the slider, the view of my entire plot resets. In other words, any rotating I did with my mouse goes away. How do I prevent the view from resetting every time I use the slider callback function?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 28 Feb 2020
Edited: MathWorks Support Team on 28 Feb 2020
In general, if you want to update a plot's data without regenerating the entire thing, save your plot object as a public property in App Designer. Then, in callbacks, instead of replotting the old and new data, simply edit the "XData", "YData", or "ZData" properties of your plot object.
----------
In this specific case, you replot everything from scratch using "fill3" in your slider callback. Thus, the plot is regenerated and goes back to its original view. To avoid this issue, save your patches as public properties:
app.Patches = fill3(...)
In your slider callback for the slider, instead of calling the "fill3" function with all the original and new data, simply access the Patch object for the black line and edit its "ZData" property according to the new value given by the slider:
blackLine = handles.patches(end);
blackLine.ZData = ...
This will update the black line without regenerating the entire plot.
----------
Attached is an example of how to do this in App Designer.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!