Show image based on radio button selecetion with push button

6 visualizzazioni (ultimi 30 giorni)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
choice_location = get(handles.buttongroup,'SelectedObject');
choice = get(choice_location,'String');
if choice == 'Progresive Rock'
imshow('pink_floyd.jpg')
end
so this is my gui's pushbutton part and my problem is if i add another if statement the new one wont work and i will get this error:
Error using ==
Matrix dimensions must agree.
Error in untitled1>pushbutton1_Callback (line 92)
if choice == 'Progresive Rock'
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)untitled1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
how can i add more statement for those radio buttons to my push button?

Risposta accettata

Geoff Hayes
Geoff Hayes il 14 Apr 2020
Yunus - when you are comparing strings, you need to use strcmp or strcmpi (else you will get the error you describe above since you are comparing two strings of different dimensions). Just change the code to
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
choice_location = get(handles.buttongroup,'SelectedObject');
choice = get(choice_location,'String');
if strcmp(choice, 'Progresive Rock')
imshow('pink_floyd.jpg')
end

Più risposte (0)

Categorie

Scopri di più su Just for fun in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by