time between many keyPressFcn actions

hello in a Gui project I have the oppening_function(the main one) and a KeyPressFcn(the one that reads some keyboard input) I need to plot an histogram on an axis that tells the average rythm of any key press. I though on using some global variable that uses tic...toc mechanism and pass it to the main function and perform some calculations

Answers (1)

David - I would discourage you from using global variables. Instead, use the handles structure to store your user-defined data, in this case an array of response times. For example, suppose your key press function is defined as
function keyPressFcnCallback(hObject, event)
handles = guidata(handles);
if ~isfield(handles,'responseTimes')
handles.responseTimes = [];
end
handles.responseTimes = [handles.responseTimes ; toc];
guidata(hObject,handles);
tic;
% etc.
In the above, we are assuming that hObject corresponds to the figure that the key press function is associated with. We use guidata to get the handles structure for the GUI and then use isfield to see if the repsonseTimes array is a field within that structure. (If not, we create it.) We then update this array with the new response time and then use guidata to save the updated handles structure.
Try implementing the above and see what happens!

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 18 May 2016

Answered:

on 25 May 2016

Community Treasure Hunt

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

Start Hunting!