Adjust the view of UIAxes

I plot a stl file by pressing a button. Then I rotate it around and change the view. And when I click on the button again, the view goes back to the default position.
I don't want it to go back to the deafult. I want it to use the latest view. But this doesn't work and still goes back to the default:
function ButtonPushed(app, event)
X = get(app.UIAxes,"View");
set ( app.UIAxes,"View", X);
data = stlread ("model.stl");
trisurf (data,'Parent', app.UIAxes);
end

 Accepted Answer

Try
function ButtonPushed(app, event)
X = app.UIAxes.View;
data = stlread ("model.stl");
trisurf (data,'Parent', app.UIAxes);
drawnow;
app.UIAxes.View = X;
end

8 Comments

Pelajar UM
Pelajar UM on 30 May 2022
Edited: Pelajar UM on 30 May 2022
Thanks a lot. This works but you can see that the view angle is being changed (first it goes to default and then immediately to the new angle). Is there a way to set the view before plotting the stl, so that you cannot see the switching?
Edit: I could do this by removing "drawnow" but somehow then I cannot rotate the model. When I click, it pans instead....
You could try moving the drawnow() to below setting the View.
I have been working on a different question having to do with App Designer in which the user was getting strange angles and sizes, and setting the view was not working; the workaround there was to drawnow() before setting view. (I suspect the matter was related to the CameraPosition the user had set.)
Thanks. Moving the drawnow to below setting the View is the same as removing it.
It works but then I cannot rotate the model unless I add:
rotate3d (app.UIAxes, "on");
but in that case the zoom feature is disabled.
Historically those operations were mutually exclusive. I don't know about app designer in that regard.
I see. Is there a way to combine the click with a key to switch between zoom and rotate?
In a typical 3D/CAD software, you hold down Ctrl or shift and then you can rotate.
I do not know with regards to app designer.
For anyone else wondering, this works:
ax=app.UIAxes;
ax.Interactions = [rotateInteraction zoomInteraction];
Oh, that looks useful!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!