Effacer les filtres
Effacer les filtres

Output of values via a callback function

12 vues (au cours des 30 derniers jours)
Tim
Tim le 7 Fév 2023
Hello all,
I am currently working with the data acquisition toolbox to record data from an accelerometer. This also works so far. However, I would like to plot this measurement data live so that the data runs smoothly and is not only updated 10 times per second (ScansAvailableFcnCount = 10 Hz). Conversely, this means that I have to save the data respectively output it from the function. This is exactly where I get stuck, because "data" is not output. I am aware that I did not specify the output value when I called the function, but I do not know where I do this or whether it works at all.
Maybe my approach is too complicated and someone has a simpler solution.
Thank you for your help,
many greetings
Tim
dq = daq('ni');
dq.Rate = 1000;
addinput(dq, 'Dev1', 'ai0', 'Voltage');
addinput(dq, 'Dev1', 'ai1', 'Voltage');
addinput(dq, 'Dev1', 'ai2', 'Voltage');
dq.ScansAvailableFcn = @(src,evt) readDataAvailable(src, evt);
start(dq, "Duration", seconds(5))
function data = readDataAvailable(src, ~)
[data, timestamps, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
end

Réponse acceptée

Jan
Jan le 7 Fév 2023
Callbacks do not have an output. Store obtained data in the UserData or ApplicationData of the calling object.
  2 commentaires
Stephen23
Stephen23 le 7 Fév 2023
Jan
Jan le 7 Fév 2023
This suggestion is smart also. Thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 7 Fév 2023
For this particular question you could addpoints to an animatedline inside the callback function. Each press of the button callback adds (x, x.^2) for the next integer value x to the line. I used the UserData property of the button to store the handle to the animated line and the next x value to be added to the plot.
I even added a pause statement (to give you the opportunity to click on some points) then used getpoints on the animatedline to retrieve the points the callback added to it.
L = animatedline(Marker = "o");
h = uicontrol(Style = "push", ...
UserData = struct('x', 1, 'L', L), ...
Callback = @addPointsToLine);
pause(10)
[x, y] = getpoints(L)
function addPointsToLine(thebutton, varargin)
newx = thebutton.UserData.x;
thebutton.UserData.x = newx+1;
addpoints(thebutton.UserData.L, newx, newx.^2);
end

Catégories

En savoir plus sur View and Analyze Simulation Results dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by