Help and Support on GUIDE - Pop up menu condition push button

1 次查看(过去 30 天)
Dear All,
I am creating a GUI to display the result (output) of combining three strings, each string from the 3 popup menus namely ‘A’, ‘B’ and ‘C’ with GUIDE.
The popup menu ‘A’ contains four strings: 0.0 to 0.25, 0.25 to 0.5, 0.5 to 0.75 and 0.75 to 1.0; popup menu ‘B’ contains the following 4 strings: K1, K2, K3 and K4 while popup menu ‘C’ contains the following 4 strings: L1, L2, L3 and L4.
I also have one static text ‘Display’ for displaying the output (result) of the combination of the 3 strings, selecting one string each, from the 3 popup menus.
Lastly, I have one condition pushbutton ‘Combine’ which function is to send the result of combining a set of 3 strings to the static text ‘Display’, after pressing the condition pushbutton which will use a series of nested If-elseif-else-end statements to test each of the conditions in order to determine and display an appropriate output (result) for each combination of the three strings.
For instance, if string 0.0 to 0.25 was selected from popup menu ‘A’, string K1 from popup menu ‘B’ and string L1 from popup menu ‘C’, the popup menu could send a word, e. g. Lion or any other word as a result (output) to the static text ‘Display’.
Also, if string 0.25 to 0.5 was selected from popup menu ‘A’, string K2 from popup menu ‘B’ and string L2 from popup menu ‘C’, the popup menu could send a word, e. g. Elephant or any other word as a result (output) to the static text ‘Display’.
Also, if string 0.5 to 0.75 was selected from popup menu ‘A’, string K3 from popup menu ‘B’ and string L3 from popup menu ‘C’, the popup menu could send a word, e. g. Tiger or any other word as a result (output) to the static text ‘Display’.
Also, if string 0.75 to 1.0 was selected from popup menu ‘A’, string K4 from popup menu ‘B’ and string L4 from popup menu ‘C’, the popup menu could send a word, e. g. Leopard or any other word as a result (output) to the static text ‘Display’.
Summarily, I have 3 popup menus ‘A’, ‘B’ and ‘C’, 1 static text ‘Display’ and 1 condition pushbutton ‘Combine’ on a figure (figure1).
Kindly do the needful.
Cheers.
  4 个评论
Rik
Rik 2022-10-22
You should not use == to compare two char vectors. That is probably what is going wrong here.
What you also might want to reconsider is your use of GUIDE. Fully building your GUI from code makes you have much more control and flexibility.
Also, please do not post duplicate questions.
Gbola
Gbola 2022-10-25
Dear All,
Thanks for your assistance.
The answer has not helped to resolve my question. I don't know what is supposed to be written under each popup menu callback (that is, popupmenu1, popupmenu2 and popupmenu3) as well as what is supposed to be written under the push button callback (that is pushbutton1). I am still getting the error messages below:
>> animals
Undefined function or variable 'popupValue1'.
Error in animals>pushbutton1_Callback (line 232)
if popupValue1=='0.0-0.25' && popupValue2==K1 && popupValue3==L1
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback.
Cheers.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2022-10-22
Do not do this:
popupValue1 = get(popupmenu1.handles,'value');
It's handles that comes first, not the control name. So it should be this (and switching to OOP style).
popupValue1 = handles.popupmenu1.Value; % Get index of selected item. 1, 2, 3, etc.
and check the index of the item you want, not the string. You had this originally:
if popupValue1==1 && popupValue2==1 && popupValue3==1
However, the indexes you want start with number 2 since the index = 1 are just things like "Select M".
  3 个评论
Image Analyst
Image Analyst 2022-10-26
Why are you not using the code I gave you? For example instead of
if popupValue1==1 && popupValue2==1 && popupValue3==1
you're doing
if popupValue1=='0.0-0.25' && popupValue2==K1 && popupValue3==L1
like I said, make the values the Value of the popup, and compare them to numbers, not strings. Every callback where you have that if block, you should get all popup values directly using the known name of the popup control:
popupValue1 = handles.popupmenu1.Value; % Get index of selected item. 1, 2, 3, etc.
popupValue2 = handles.popupmenu2.Value; % Get index of selected item. 1, 2, 3, etc.
popupValue3 = handles.popupmenu3.Value; % Get index of selected item. 1, 2, 3, etc.
if popupValue1==1 && popupValue2==1 && popupValue3==1
Gbola
Gbola 2022-10-29
移动:Voss 2022-12-28
Dear All,
Many thanks for your time and help.
The answer has helped partially to resolve my question. But I have got some error messages which are stated below:
I have attached the animals.fig and the animals.m file for your perusal.
>> animals
Error using feval
Undefined function 'animals_OutputFcn' for input arguments of type 'struct'.
Error in gui_mainfcn (line 265)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error using feval
Undefined function 'pushbutton1_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Error using feval
Undefined function 'popupmenu1_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Error using feval
Undefined function 'popupmenu2_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('popupmenu2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Error using feval
Undefined function 'popupmenu3_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('popupmenu3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Error using feval
Undefined function 'pushbutton1_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in animals (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)animals('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Thanks.

请先登录,再进行评论。


Image Analyst
Image Analyst 2022-10-30
It looks like you added an "end" statement at the end of every function. You should not do that. Take most of your end's out. If you can do that, then just recreate the GUI from scratch but don't add any "end"s to close off the functions.
  19 个评论
Image Analyst
Image Analyst 2023-1-7
Chances are no one has an 11 year old version anymore.
By the way @Gbolagade Kola ADEGOKE, are you the same person as @Gbola?
Rik
Rik 2023-1-8
I will not even attempt this conversion, nor do I expect anyone else will. This is an important reason why you should not use GUIDE. It is a mess to keep compatible, even if all the functions are compatible. I know, since I try to ensure my code on the File Exchange is compatible with most releases.
Recently I had some trouble starting older releases, so I might not even be able to help you in the first place.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by