Displaying figure from function in MATLAB gui
29 views (last 30 days)
Show older comments
Jonathan Lam
on 9 Jul 2024 at 21:44
Commented: Voss
on 10 Jul 2024 at 14:44
Hello, I have this function that takes a value Val and returns a 3D plot of two curves z1 and z2 with a dotted red line where they intersect with Val.
function Plot(Val)
X = [0:0.5:5];
Y = [0:0.1:1];
[x,y] = meshgrid(X,Y);
z1 = [x.*y.*57.5];
z2 = [x.*y.*110];
figure(1)
surf(x,y,z1, 'FaceAlpha', 0.5)
colormap winter
shading interp
hold on
surf(x,y,z2, 'FaceAlpha', 0.5)
shading interp
xlim([0 5])
ylim([0 1])
zlim([0 450])
Xg = x(1,:);
Yg = y(:,1);
hold on
M1 = contour3(Xg, Yg, z1, [CharVal,CharVal], '--r');
M2 = contour3(Xg, Yg, z2, [CharVal, CharVal], '--r');
I'm trying to create an app in the MATLAB gui where I have a slider for Val and would be able to see the intersection point change in real time. I currently am trying to use just a numeric input field for the value, but I can't get the figure to plot in my GUI.
% Button pushed function: ExecuteButton
function ExecuteButtonPushed(app, event)
CharVal = app.EffValueEditField.Value;
EnergyEff(CharVal);
plot(, 'Parent', app.UIAxes);
end
Inputting a value and clicking the 'Execute' button gives me the plot but outside of the GUI. Any help is appreciated
Accepted Answer
Walter Roberson
on 10 Jul 2024 at 1:13
function Plot(Val, ax)
X = [0:0.5:5];
Y = [0:0.1:1];
[x,y] = meshgrid(X,Y);
z1 = [x.*y.*57.5];
z2 = [x.*y.*110];
surf(ax, x, y, z1, 'FaceAlpha', 0.5)
colormap(ax, 'winter')
shading(ax , 'interp')
hold(ax, 'on')
surf(ax, x, y, z2, 'FaceAlpha', 0.5)
shading(ax, 'interp');
xlim(ax, [0 5])
ylim(ax, [0 1])
zlim(ax, [0 450])
Xg = x(1,:);
Yg = y(:,1);
hold(ax, 'on')
M1 = contour3(ax, Xg, Yg, z1, [CharVal,CharVal], '--r');
M2 = contour3(ax, Xg, Yg, z2, [CharVal, CharVal], '--r');
end
% Button pushed function: ExecuteButton
function ExecuteButtonPushed(app, event)
CharVal = app.EffValueEditField.Value;
Plot(CharVal, app.UIAxes);
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Map Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!