Trying to Program a Switch-Case Expression for a Pop-up Menu in a MATLAB GUI
Mostrar comentarios más antiguos
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);
Respuesta aceptada
Más respuestas (2)
Caleb
el 19 de Jul. de 2012
5 comentarios
Caleb
el 19 de Jul. de 2012
Walter Roberson
el 20 de Jul. de 2012
What input arguments? You aren't passing any input arguments?
But @imdilate should only be creating a function handle, not calling imdilate.
What happens if you type
@imdilate
at the command prompt?
Walter Roberson
el 20 de Jul. de 2012
Wait... just how old is your MATLAB?
Caleb
el 23 de Jul. de 2012
Caleb
el 23 de Jul. de 2012
Sean de Wolski
el 19 de Jul. de 2012
Editada: Sean de Wolski
el 19 de Jul. de 2012
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};
4 comentarios
Caleb
el 19 de Jul. de 2012
Walter Roberson
el 19 de Jul. de 2012
Your code had
val = get(hObject, 'Value');
so Sean used that.
Just make sure your ops structure is in the same order as the entries in your String property.
Sean de Wolski
el 19 de Jul. de 2012
It should just be:
imshow(handles.image2,'parent',handles.axes2);
Categorías
Más información sobre Functions en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!