Gui displaying different pictures for wrong and right answers

1 view (last 30 days)
I am trying to figure out how to show different picture with clicking push button on gui.
I want it to show good pictures for right answer while showing sad pictures for getting wrong How can i do that?
% --- Executes on button press in yespushbutton1.
function yespushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to yespushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=1
if a==handles.testvalue;
handles.correct=1;
im = handles.pic{handles.reward_value};
image(im,'parent',handles.axes1);
handles.reward_value = rem(handles.reward_value,6) + 1;
elseif a~=handles.testvalue;
handles.correct=0;
im = handles.pic{handles.reward_value};
image(im,'parent',handles.axes1);
handles.punish_value = rem(handles.punish_value,3) + 1;
% im = handles.pic{handles.reward_value};
% image(im,'parent',handles.axes1);
% handles.reward_value = rem(handles.reward_value,9) + 1;
  1 Comment
Geoff Hayes
Geoff Hayes on 15 Nov 2014
It seems that you have the correct idea in displaying an image based on whether the user has given the right answer. Though it isn't clear why you use the local variable a or set the handles.correct to be one without updating the handles structure after.
Your handles structure has a cell array of images, handles.pic, of which the same image is loaded to the axes whether the user has given the correct response or not. Is this intentional?
What problems are you experiencing with this code? If you are observing any errors, please post the full error message.

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!