Disable option on a popupmenu

5 次查看(过去 30 天)
Stefany Romero
Stefany Romero 2019-9-30
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:
1.png 2.png
I'm working with GUIDE and and when i run my program MATLAB show me the next error:
000.png
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 个评论
Walter Roberson
Walter Roberson 2019-10-1
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.
Stefany Romero
Stefany Romero 2019-10-1
:(
Can you help me fixing those errors please?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2019-10-1
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 个评论
Walter Roberson
Walter Roberson 2019-10-1
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.
Stefany Romero
Stefany Romero 2019-10-1
Finally work dear Walter, thanks a lot.

请先登录,再进行评论。

类别

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