UICONTROL: How can I make a callback of an m-file and depending on the value make an appropriate uicontrol on the first m-file

조회 수: 1 (최근 30일)
Hello,
I am trying to make a pop-up window with inputs using UICONTROL.
The problem is that I want in this pop-up window to make a selection pop-up menu like in the following code, that depends on the previous selection (by the user).
In my example, the window pop-ups, the user selects the type of the battery (Lead Acid, Lithium Ion, Salt Water). Now, dependin on this value I want the next selection menu to change. Let's say for example, if the user selects 'Lead Acid', the next menu to say 'Select', 'Type A1', 'Type A2', if the user selects 'Lithium Iion', the next menu to say 'Select', 'Type B1', 'Type B2' and finally if the user selects 'Salt Water', the next menu to say 'Select', 'Type C1', 'Type C2'
My main m-file is the following:
function fig = calc(command_str);
% texts
h0 = figure('Units','normalized', ...
'Color',[0.8 0.8 0.8], ...
'FileName','calc.m', ...
'MenuBar','none', ...
'Name',' Calculator', ...
'NumberTitle','off', ...
'PaperPosition',[18 180 576 432], ...
'PaperUnits','points', ...
'Position',[0.15 0.2 0.35 0.75], ...
'Resize','off', ...
'Tag','calculator', ...
'ToolBar','none');
h1 = uicontrol('Parent',h0, ...
'Units','normalized', ...
'FontUnits','normalized', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontName','Arial', ...
'FontSize',0.6, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',[0.18 0.51 0.43 0.04], ...
'String','Type Of Battery', ...
'Style','text');
h1 = uicontrol('Parent',h0, ...
'Units','normalized', ...
'FontUnits','normalized', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontName','Arial', ...
'FontSize',0.6, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',[0.18 0.45 0.43 0.04], ...
'String','Battery Model', ...
'Style','text');
% Edits
h1 = uicontrol('Parent',h0, ...
'Units','normalized', ...
'FontUnits','normalized', ...
'BackgroundColor',[1 1 1], ...
'Callback','inter2 BatType', ...
'FontName','Arial', ...
'FontSize',0.6, ...
'ListboxTop',0, ...
'Position',[0.7 0.51 0.2 0.05], ...
'String',['Select... ';'Lead Acid '; 'Lithium-Ion '; 'Salt Water '], ...
'Style','popupmenu', ...
'Tag','BatType', ...
'Value',1);
h1 = uicontrol('Parent',h0, ...
'Units','normalized', ...
'FontUnits','normalized', ...
'BackgroundColor',[1 1 1], ...
'Callback','inter2 BatModel', ...
'FontName','Arial', ...
'FontSize',0.6, ...
'ListboxTop',0, ...
'Position',[0.7 0.45 0.2 0.05], ...
'String',['Select... ';'Type A '], ...
'Style','popupmenu', ...
'Tag','BatModel', ...
'Value',1);
end
My next m-file should read the value of the first selection menu, but also somehow call the first m-file in order to change the second selection menu accordingly.
function inter2(action)
switch(action)
case 'BatType'
BatType_inp = get(findobj(gcf,'Tag','BatType'),'Value');
if BatType_inp == 2
...
end
...
end
Could you please help me with this?
Thank you very much! I really appreciate your time!!!

채택된 답변

PETROS
PETROS 2019년 1월 16일
I found it!
In the second m-file the case of reading the value of the first selection menu, should be:
case 'BatType'
BatType_inp = get(findobj(gcf,'Tag','BatType'),'Value');
if BatType_inp == 2
set(findobj(gcf,'Tag','BatModel'), 'String', {'Model A1', 'Model A2', 'Model A3'}, 'Value', 1);
elseif BatType_inp == 3
set(findobj(gcf,'Tag','BatModel'), 'String', {'Model B1', 'Model B2', 'Model B3'},'Value', 1);
else
set(findobj(gcf,'Tag','BatModel'), 'String', {'Model C1', 'Model C2', 'Model C3'}, 'Value', 1);
end
Thank you very much all of you for reading my question and of course for trying to solve it!
Thank you very much!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by