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
回答(1 个)
Geoff Hayes
2016-5-25
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!
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!