If statement involving GUI criterias
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I am building a GUI and I am not able to execute a case in the execution.
I have an uipanel in which there is a radiobutton and a popupmenu( those 2 button are linked somehow). When clicking on the radiobutton I am able to select 3 options in the popupmenu, where there are 3 strings( X-ALL, X - GOODS, X- SERVICES) in my popupmenu.
so i wrote a get eventdata, to get the tags of each radiobutton then I used the switch in order to differentiate between the cases
the radiobutton connected to the popupmenu has a value of 1.
so my IF statement is
if get(handles.radiobutton4,'Value') == 1 & strcmp('X - All', get(handles.popupmenu1,'String'))
msgbox('test')
else
msgbox('KO')
end
I am getting KO.
I know there is an issue on this part of the statement strcmp('X - All', get(handles.popupmenu1,'String'))
because this gives an array as follows :
1 0 0
so my question is how to make the the statement take only the first element of the 'String Array' and compare it with the value of radiobutton...
Itried str2num but it didnt work...
Thank you very much
D
댓글 수: 0
채택된 답변
Image Analyst
2014년 9월 1일
Don't do this: strcmp('X - All', get(handles.popupmenu1,'String'))
Like you said, you get a vector of how the 'X - All' string matches each of the 3 strings in the popup. What get(handles.popupmenu1,'String') actually gives you is a cell array of all the strings in the popup , not the text of the one item you selected.
What you should do is to know what item 'X - All' occurs at. Let's say it's number 3. Then you use value, not string:
selectedItem = get(handles.popupmenu1, 'value');
if get(handles.radiobutton4,'Value') == 1 && selectedItem == 3
If the items may be at unknown locations (3 sometimes, 2 other times, etc.) then you need to use strcmp but you need to get the string item, not the logical selection vector
allStrings = get(handles.popupmenu1, 'String');
selectedValue = get(handles.popupmenu1, 'value');
selectedString = allStrings{selectedValue};
Again, the first chunk of code is preferred if the items are always at the same number in the list, while the second one is more flexible but more complicated.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!