Replotting a 2D graph on a 3D surface keeps all 3 axes
13 views (last 30 days)
Using app designer, I have one UIAxis that allows the user to switch between a 2D line plot and a 3D surface plot. When switching from the 3D plot to the 2D plot the z-axis remains which it is not supposed to. The user should be able to switch between as much as they want.
if app.DButton.Value == 1 % 2D check selected
plot(app.UIAxes,app.xaxis,app.yaxis) % plot 2 graph
app.graph = app.UIAxes.Children;
else % else 3D check selected
[X,Y] = meshgrid(app.xaxis,app.yaxis);
[Z] = meshgrid(app.zaxis);
surf(app.UIAxes,X,Y,Z) % 3D surface plot
I'm using cla(app.UIAxes) to reset the axis every time the radiobutton is changed but for some reason the plot is keeping the z-axis even though the code has plot(x,y).
It's supposed to be:
What is actually being plot:
Any help would be appreciated.
Dave B on 17 Mar 2022
Edited: Dave B on 17 Mar 2022
cla doesn't reset the view.
Here are some options:
Set the view explicitly: view(app.UIAxes, 2)
Call cla with the reset flag, which will reset the axes to its original state (including getting rid of the labels and other things you've done to configure it): cla(app.UIAxes ,'reset')
Note the presence/absence of the grid in the examples below, surf turns on the grid (if you haven't set it explicitly elsewhere), cla doesn't turn it off, but cla('reset') does.