Show image based on radio button selecetion with push button
6 views (last 30 days)
Show older comments
Yunus Alperen
on 14 Apr 2020
Commented: Yunus Alperen
on 14 Apr 2020
% --- 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?
0 Comments
Accepted Answer
Geoff Hayes
on 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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!