How to update 3D plot in real time with slider?
19 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-10-14
编辑: MathWorks Support Team
2020-2-28
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?
采纳的回答
MathWorks Support Team
2020-2-28
编辑:MathWorks Support Team
2020-2-28
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!