Disable option on a popupmenu

조회 수: 5 (최근 30일)
Stefany Romero
Stefany Romero 2019년 9월 30일
댓글: Stefany Romero 2019년 10월 1일
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