switch function in GUI

4 ビュー (過去 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by