Output of values via a callback function
조회 수: 15 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
추가 답변 (1개)
Steven Lord
2023년 2월 7일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Counter and Timer Input and Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!