Displaying figure from function in MATLAB gui

조회 수: 6 (최근 30일)
Jonathan Lam
Jonathan Lam 2024년 7월 9일
댓글: Voss 2024년 7월 10일
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
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개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by