Disable option on a popupmenu

5 Ansichten (letzte 30 Tage)
Stefany Romero
Stefany Romero am 30 Sep. 2019
Kommentiert: Stefany Romero am 1 Okt. 2019
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 Kommentare
Walter Roberson
Walter Roberson am 1 Okt. 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.
Stefany Romero
Stefany Romero am 1 Okt. 2019
:(
Can you help me fixing those errors please?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 1 Okt. 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 Kommentare
Walter Roberson
Walter Roberson am 1 Okt. 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.
Stefany Romero
Stefany Romero am 1 Okt. 2019
Finally work dear Walter, thanks a lot.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by