switch function in GUI

4 views (last 30 days)
PC
PC on 5 Dec 2013
Commented: bhawesh pathak on 21 Apr 2019
I am learning GUI through this youtube Video which is uploaded by matlab.
I tried to follow and write down everything but I got error message while using the pop up button. The related error is the usage of switch function.
here are parts of the code of the GUI.
- - - - - - - - - - - -
% --- Executes on selection change in popup1.
function popup1_Callback(hObject, eventdata, handles)
% hObject handle to popup1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popup1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popup1
val = get (hObject,'Value');
str = get (hObject,'String');
switch str(val)
case 'peaks'
handles.current_data = handles.peaks;
case 'membrane'
handles.current_data = handles.membrane;
case 'sinc'
handles.current_data = handles.sinc;
end
guidata(hObject, handles);
- - - - - - - - - - - -
the error messages are:
??? SWITCH expression must be a scalar or string constant.
Error in ==> test2>popup1_Callback at 204 switch str(val)
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> test2 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)test2('popup1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
- - - - - - - - - - - - Thank you.
  1 Comment
bhawesh pathak
bhawesh pathak on 21 Apr 2019
Write Switch str{Val}; Instead of str(Val)

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!