Displaying figure from function in MATLAB gui
4 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Walter Roberson
2024-7-10
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Map Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!