필터 지우기
필터 지우기

switch function in GUI

조회 수: 1 (최근 30일)
PC
PC 2013년 12월 5일
댓글: bhawesh pathak 2019년 4월 21일
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
bhawesh pathak
bhawesh pathak 2019년 4월 21일
Write Switch str{Val}; Instead of str(Val)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by