Update matrix inside KeyPressFcn
Show older comments
I'm trying to update a matrix with response times inside a function within KeyPressFcn in a figure. how can i do that?
my code (not working, 'responses' doesn't get updated):
hf=figure('Toolbar','none','Menubar','none','NumberTitle','off',...
'Units','normalized','position',[0 0 1 1],'Color',[1 1 1]);
for trial = 2:trial_num
tic
set(hf, 'KeyPressFcn', ...
@(fig_obj , eventDat) myFunction(fig_obj, eventDat, trial, same_or_not, yes_no,toc, responses));
pause(0.05)
axis off
set(letter_text,'String',trial_letters(trial))
pause(0.75)
axis off
set(letter_text,'String','')
set(yes_no,'String','')
end
function myFunction(~, eventDat, trial, same_or_not, yes_no, toc, responses)
key = eventDat.Key;
if (key == 'space')
responses(trial,1) = 1;
responses(trial,4) = toc;
if (same_or_not(trial) == 1)
set(yes_no,'String','yes')
set(yes_no,'Color',[0 1 0])
else
set(yes_no,'String','no')
set(yes_no,'Color',[1 0 0])
end
end
end
Thanks
1 Comment
As an aside, for callback functions it is often simpler to use the cell array syntax rather than defining an anonymous function:
set(hf, 'KeyPressFcn', {@myFunction, trial, same_or_not, yes_no,toc, responses});
The called function remains the same.
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!