Passing a variable from the uislider callback function

조회 수: 1 (최근 30일)
Kyle McManus
Kyle McManus 2018년 7월 26일
댓글: Stephen23 2018년 7월 27일
I want to pass the variables sldValue1, sldValue2 and sldValue3 from the uislider callback functions outside of the sliderMoving1, sliderMoving2 and sliderMoving3 functions. I have three sliders and the equation I am solving for depends on three variable inputs, all of which I am leaving up to the user to determine (it's for tail design/flight control). The code below gives the snippit of the interface I am working on.
In short, I want to be able to call sldValue1, 2, and 3 outside of the sliderMoving1, 2 and 3 callbacks in real time when the values are changed. Thank you in advance!
GUI = uifigure('Name','Aircraft Optimization',...
'NumberTitle', 'off','Position', [100 100 1300 800])
pnl_6 = uipanel('Parent',GUI,'Title',...
strcat('Control Panel'),...
'FontSize',12,...
'Position', [662.5 10 183.75 452]);
pnl_8 = uipanel('Parent',pnl_6,'Position', [5 300 173.75 120]);
pnl_9 = uipanel('Parent',pnl_6,'Position', [5.25 160 173.75 120]);
pnl_10 = uipanel('Parent',pnl_6,'Position', [5 20 173.75 120]);
aeroCenter = 0;
gravityCenter = 0;
distanceCGaheadAC = 0;
fuselageLength = 1; %
uilabel(pnl_8,'Text','Aerodynamic Center',...
'Position',[11.875 95 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
uilabel(pnl_8,'Text','Percent of Wing MAC',...
'Position',[11.875 75 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
sld_1 = uislider(pnl_8,'Position',[11.875 65 150 3],...
'ValueChangedFcn',@(sld,event)...
sliderMoving1(sld));
sld_1.Limits = [20 30];
sld_1.Value = 25;
uilabel(pnl_8,'Text',strcat(num2str(aeroCenter),32,'%'),...
'Position',[11.875 5 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
uilabel(pnl_9,'Text','Center of Gravity',...
'Position',[11.875 95 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
uilabel(pnl_9,'Text','Percent of Fuselage',...
'Position',[11.875 75 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
sld_2 = uislider(pnl_9,'Position',[11.875 65 150 3],...
'ValueChangedFcn',@(sld,event)...
sliderMoving2(sld));
sld_2.Limits = [10 90];
sld_2.Value = 50;
uilabel(pnl_9,'Text',strcat(num2str(gravityCenter),32,'%'),...
'Position',[11.875 5 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
uilabel(pnl_10,'Text','Distance CG is',...
'Position',[11.875 95 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
uilabel(pnl_10,'Text','Ahead of AC in Meters',...
'Position',[11.875 75 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
sld_3 = uislider(pnl_10,'Position',[11.875 65 150 3],...
'ValueChangedFcn',@(sld,event)...
sliderMoving3(sld));
sld_3.Limits = [round(-(fuselageLength/4),1)...
round((fuselageLength/4),1)];
sld_3.Value = 0;
uilabel(pnl_10,'Text',strcat(num2str(distanceCGaheadAC),32,'(m)'),...
'Position',[11.875 5 150 20],...
'HorizontalAlignment','center','FontWeight','bold');
function sliderMoving1(sld_1)
sldValue1 = (sld_1.Value)/100
end
function sliderMoving2(sld_2)
sldValue2 = (sld_2.Value)/100
end
function sliderMoving3(sld_3)
sldValue3 = (sld_3.Value)
end
  댓글 수: 1
Stephen23
Stephen23 2018년 7월 27일
If you are using GUIDE then use guidata. If you are sensibly writing your own GUI then use nested functions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by