Pop UP menu in GUIDE

6 vues (au cours des 30 derniers jours)
Sam
Sam le 20 Mar 2012
Hello i am developping an interactive GUI for my identification method which is of ellipsoidal type. But my issue is pretty trivial to GUIDE developpers. i have a problem with following:
i want to create a popup menu with three options, now i know that i should change/populate the needed script to be executed in the Callback function "in the switch cases". what i wanna do is for example when a user chooses a case 1, a m file function gets executed. similarly second case, a second function gets executed with a different purpose.
let's say my function is called RLS.m, second LS.m, and the thrid is ESM.m so this did not work
function popupmenu1_Callback(hObject, eventdata, handles)
str = get(hObject, 'String'); val = get(hObject,'Value');
switch str{val}; case 'Ellipsoidal Set Estimation' % User selects peaks. feval('ESM'); case 'Recursive Least Square Estimation' % User selects membrane. feval('RLS'); : : end % Save the handles structure. guidata(hObject,handles)
help would be appreciated

Réponses (2)

Arthur
Arthur le 20 Mar 2012
feval uses function handles rather than the name of the function. But I think you don't need feval at all. If your functions are on the matlab search path, you can just call the function directly. Also, you do not need to read the String of your popup. I usually just use the value of the popup, which is easier to program, and allows you to change the String of the popup while the GUI is running.
I suggest to try this:
function popupmenu1_Callback(hObject, eventdata, handles)
val = get(hObject,'value');
switch val
case 1
RLS;
case 2
LS;
case 3
ESM;
end
  1 commentaire
Sam
Sam le 20 Mar 2012
Arthur thanks for your reply
i actually attemtped that initially but didn't work. i redid this as u suggested it didn't launch the function, the popup changes the values "in this case between the RLS and ESM" but there is no function being launched. does this have anything to do with varargin

Connectez-vous pour commenter.


Sam
Sam le 20 Mar 2012
Arthur thanks for your reply
i actually attemtped that initially but didn't work. i redid this as u suggested it didn't launch the function, the popup changes the values "in this case between the RLS and ESM" but there is no function being launched. does this have anything to do with varargin
  3 commentaires
Sam
Sam le 20 Mar 2012
Actually i'm not getting any error
but the function does not run...i reduced it so to debug , and here is how it looks
function popupmenu1_Callback(hObject, eventdata, handles)
str = get(hObject, 'String');
val = get(hObject,'Value');
% Set current data to the selected data set.
switch val;
case 'Ellipsoidal Set Estimation' % User selects peaks.
Ellipsoidal_Algorithm;
case 'Recursive Least Square Estimation' % User selects membrane.
return;
end
% Save the handles structure.
guidata(hObject,handles)
Arthur
Arthur le 21 Mar 2012
Your switch uses 'val', which will have value 1,2 or 3, whereas your cases are still strings. Change the cases to numbers and it should work. Also, you might want to include an 'otherwise' statement in your switch. This makes it easier to debug.
try this:
function popupmenu1_Callback(hObject, eventdata, handles)
str = get(hObject, 'String');
val = get(hObject,'Value');
% Set current data to the selected data set.
switch val;
case 1 % User selects peaks.
Ellipsoidal_Algorithm;
case 2% User selects membrane.
return;
otherwise
error('Invalid value');
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by