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

Réponses (1)

Geoff Hayes
Geoff Hayes le 25 Mai 2016
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!

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by