Hi JJ,
I understand that you are trying to create an interactive 3D ellipsoid in App Designer using a knob but are facing several issues like the axis limits resetting, the ellipsoid not resizing properly with changes in the knob value (“D”), and also unwanted figure windows opening each time the value is adjusted.
This is because the axes are not being cleared before plotting a new ellipsoid, and axis limits are not being explicitly set, which causes MATLAB to default them to “[0 1]”. Also, some plotting functions like “patch” can open new figure windows if not correctly linked to the App Designer’s “UIAxes”.
To fix this, you need to do the following:
- Clear the axes before each plot using “cla(app.UIAxes);”
- Manually set axis limits with “xlim”, “ylim”, and “zlim”.
- Ensure that all plotting commands are linked to “app.UIAxes” to avoid new figure windows.
Kindly refer to the following updated portion of your code:
function DamageKnobValueChanging(app, event)
D = event.Value;
Xmax = 240 * (1 - D);
Ymax = 120 * (1 - D);
Tmax = 80 * (1 - D);
x = linspace(-250, 250, 50);
[X, Y, Z] = meshgrid(x);
V = ((X.^2)/(Xmax^2) + (Y.^2)/(Ymax^2) - (X.*Y)/(Xmax^2) + (Z.^2)/(Tmax^2));
cla(app.UIAxes); % Clear previous plot
axis(app.UIAxes, 'vis3d');
xlim(app.UIAxes, [-250 250]);
ylim(app.UIAxes, [-250 250]);
zlim(app.UIAxes, [-250 250]);
hp = patch(app.UIAxes, isosurface(X, Y, Z, V, 1));
hp.EdgeColor = 'none';
hp.FaceColor = [101 119 158] / 255;
lighting(app.UIAxes, 'gouraud');
isonormals(X, Y, Z, V, hp);
camlight(app.UIAxes);
view(app.UIAxes, -20, 30);
end
With these changes, your ellipsoid should now resize correctly with the knob, stay within your App Designer UI, and should also avoid spawning new figures.
