Show image based on radio button selecetion with push button

6 vues (au cours des 30 derniers jours)
Yunus Alperen
Yunus Alperen le 14 Avr 2020
Commenté : Yunus Alperen le 14 Avr 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?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 14 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Just for fun dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by