Trying to Program a Switch-Case Expression for a Pop-up Menu in a MATLAB GUI
1 次查看(过去 30 天)
显示 更早的评论
Can someone tell me what's wrong with my syntax or any other errors you spot?
% --- Executes on selection change in popupmenu_filters.
function popupmenu_filters_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_filters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% determine which filter to apply by reading string in pop-up menu
str = get(hObject, 'String');
val = get(hObject, 'Value');
% set current filter to the user-selected filter
switch str{val};
case 'imdilate'
handles.current_filter = imdilate
case 'imerode'
handles.current_filter = imerode
case 'imopen'
handles.current_filter = imopen
case 'imclose'
handles.current_filter = imclose
case 'imtophat'
handles.current_filter = imtophat
case 'imbothat'
handles.current_filter = imbothat
case 'entropy filter'
handles.current_filter = entropyfilt
end
handles.image2 = handles.current_filter(handles.image);
handles.axes2(imshow(handles.image2));
% pushbutton_save handles structure
guidata(hObject, handles);
0 个评论
采纳的回答
Walter Roberson
2012-7-18
handles.current_filter = @imdilate;
Without the @ it is going to _ call_ imdilate with no arguments.
0 个评论
更多回答(2 个)
Sean de Wolski
2012-7-19
编辑:Sean de Wolski
2012-7-19
Rather than using switch I would package this as a cell array of function handles and then extract the value:
ops={@imdilate,@imerode,@imopen} %etc
handles.current_filter = ops{val};
另请参阅
类别
在 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!