Displaying figure from function in MATLAB gui
6 ビュー (過去 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 で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!