Pop UP menu in GUIDE
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Arthur
2012-3-20
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
Sam
2012-3-20
3 个评论
Arthur
2012-3-21
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!