Disable option on a popupmenu
12 views (last 30 days)
Show older comments
Hi guys.
I was trying to disable an option on a popupmenu1.
Because i have 2 popupmenus with the same options.
I want to disable an option when i choose the same option on both menu, for example:
If i choose the option binary on the popupmenu1 i want to disable the option "binary" on the popupmenu2.
Here i show an example that what i'm trying:
I'm working with GUIDE and and when i run my program MATLAB show me the next error:
This is my code:
popup1_choices = handles.popupmenu1.String;
source_base = popup1_choices{handles.popupmenu1.Value};
remaining_bases = setdiff(pupup1_choices,{source_base});
handles.popupmenu1.String = remaining_bases;
switch source_base
case 1
msgbox('No ha seleccionado ninguna base a convertir');
case 2
value_in_dec = bin2dec(value_in_str);
case 3
value_in_dec = hex2dec(value_in_str);
case 4
value_in_dec = sscanf(value_in_str,'%lo')
case 5
value_in_dec = sscanf(value_in_str,'%ld');
end
popup2_choices = handles.popupmenu2.String;
dest_base = popup2_choices{handles.popupmenu2.Value};
switch dest_base
case 1
msgbox('No ha seleccionado ninguna base a convertir');
case 2
value_out_str = dec2bin(value_in_dec);
case 3
value_out_str = dec2hex(value_in_dec);
case 4
value_out_str = sprintf('%lo',value_in_dec)
case 5
value_out_str = sprintf('%ld',value_in_dec);
end
handles.edit2.String = value_out_str;
5 Comments
Walter Roberson
on 1 Oct 2019
You need to go into your .fig file with GUIDE and edit the popup menu choices for your two popups. You need to remove the empty lines that you have after the Decimal choice.
You also need to make a number of other changes I already listed in your other Question, some of which I have already pointed out to you multiple times such as what your case statements need to be.
Answers (1)
Image Analyst
on 1 Oct 2019
Stefany:
If you're going to be changing the words in popup2, then you cannot check the value (selected index) of it in your switch. Because one time a 3 might mean one thing (word) and another time it might mean a different thing (different base). You'll have to extract the selected item (word) itself, not just test its index.
selectedIndex2 = handles.popupmenu2.Value;
allItems = handles.popupmenu2.String;
selectedWord = allItems{selectedIndex2};
switch selectedWord
case 'binary'
% code
case 'octal'
% code
% etc......
end
15 Comments
Walter Roberson
on 1 Oct 2019
That looks better.
Now remember to go into GUIDE and remove the empty lines from the choices for popupmenu1 and popupmenu2 . You currently have
Ninguno
Binary
Hexadecimal
Octal
Decimal
%empty line
The empty line is leading to problems.
Note: consider using the 'stable' option on the setdiff() call.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!