필터 지우기
필터 지우기

Output of values via a callback function

조회 수: 11 (최근 30일)
Tim
Tim 2023년 2월 7일
답변: Steven Lord 2023년 2월 7일
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

채택된 답변

Jan
Jan 2023년 2월 7일
Callbacks do not have an output. Store obtained data in the UserData or ApplicationData of the calling object.
  댓글 수: 2
Jan
Jan 2023년 2월 7일
This suggestion is smart also. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
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

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by