Azzera filtri
Azzera filtri

switch function in GUI

1 visualizzazione (ultimi 30 giorni)
PC
PC il 5 Dic 2013
Commentato: bhawesh pathak il 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 Commento
bhawesh pathak
bhawesh pathak il 21 Apr 2019
Write Switch str{Val}; Instead of str(Val)

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by