If statement involving GUI criterias
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Davin
el 1 de Sept. de 2014
Comentada: Davin
el 1 de Sept. de 2014
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 comentarios
Respuesta aceptada
Image Analyst
el 1 de Sept. de 2014
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Dialog Boxes en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!