Can you make a plot that updates based off a separate GUI?

I currently have some coursework to complete and would like to go above what is required. I have to create a flow visualisation plot for any NACA 4-series wing. This is what I am replicating in MATLAB.
My question is: is it possible to model the above in MATLAB but in a realtime scenario where you can dynamically change the input parameters such as freestream velocity and angle of attack of the aerofoil?
I would like to change these input parameters in a seperate GUI to the plot that has interactive dials that can adjust the input parameters and then dynamically update the plot based off of those parameters. The figure on the left is with an input parameter of 45 degrees, and the one on the right is at 15 degrees, for example.
To clarify; I do not need to simulate real time air flow over the wing, just one static case of airflow that is a function of the input parameters.
If this is possible, where would be a good place to start doing further research.
Thank you.

回答(1 个)

This is definitely possible.
In MATLAB there are two different sets of GUI components you can use. One is figure()'s and their descendants, and the other is uifigure()'s and their descendants. uifigure-type GUIs are the newer type, and there are more styles of UI components to choose from with them.
Each set has its own GUI development environment: for figures it is GUIDE; for uifigures it is AppDesigner. However, it is not necessary to use a GUI development environment at all; you can always create any type of component and control any of its properties programmatically, i.e., with code.
Here is a simple example of creating a figure-type UI programmatically. This code creates a single GUI window with an axes that contains a line. There are also two edit boxes where the user can specify the line's slope and y-intercept. When the user changes an input the line is updated.
You could modify this code to include your airflow calculations and add more UI controls as necessary to allow the user to specify the input parameters.
function line_viewer()
f = figure( ...
'Name','Line Viewer', ...
'Units','pixels', ...
'NumberTitle','off', ...
'IntegerHandle','off', ...
'HandleVisibility','off', ...
'DockControls','off');
ax = axes( ...
'Parent',f, ...
'Units','pixels', ...
'Box','on', ...
'XGrid','on', ...
'YGrid','on');
data_line = line( ...
'Parent',ax, ...
'XData',[], ...
'YData',[], ...
'LineWidth',3);
texts = [ ...
uicontrol( ...
'Parent',f, ...
'Style','text', ...
'Units','pixels', ...
'String','Slope: ', ...
'HorizontalAlignment','right') ...
uicontrol( ...
'Parent',f, ...
'Style','text', ...
'Units','pixels', ...
'String','Y-Intercept: ', ...
'HorizontalAlignment','right') ...
];
edits = [ ...
uicontrol( ...
'Parent',f, ...
'Style','edit', ...
'Units','pixels', ...
'String','1', ...
'Callback',@cb_edit) ...
uicontrol( ...
'Parent',f, ...
'Style','edit', ...
'Units','pixels', ...
'String','0', ...
'Callback',@cb_edit) ...
];
set(f,'SizeChangedFcn',@scf);
scf();
cb_edit();
function scf(~,~)
pos = get(f,'Position');
ax_wh = max(0,pos([3 4])-[200 60]);
set(ax,'Position',[35 30 ax_wh]);
set(texts(1),'Position',[50+ax_wh(1) pos(4)-50 80 20]);
set(edits(1),'Position',[132+ax_wh(1) pos(4)-50 65 20]);
set(texts(2),'Position',[50+ax_wh(1) pos(4)-80 80 20]);
set(edits(2),'Position',[132+ax_wh(1) pos(4)-80 65 20]);
end
function cb_edit(~,~)
m = str2double(get(edits(1),'String'));
b = str2double(get(edits(2),'String'));
if isfinite(m) && isfinite(b)
set(data_line,'XData',[0 1],'YData',b+[0 m]);
else
set(data_line,'XData',[],'YData',[]);
end
end
end

类别

帮助中心File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

版本

R2021b

提问:

2022-2-27

回答:

2022-2-27

Community Treasure Hunt

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

Start Hunting!

Translated by