Displaying figure from function in MATLAB gui
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonathan Lam
el 9 de Jul. de 2024
Comentada: Voss
el 10 de Jul. de 2024
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
1 comentario
Respuesta aceptada
Walter Roberson
el 10 de Jul. de 2024
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Map Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!