Send data from workspace to callback function
Mostrar comentarios más antiguos
Hi,
How can I get a value from my workspace in my callback function?
Example
% Configure a new listener to process the incoming data.
lh = addlistener(s,'DataAvailable', @stopWhenExceedOneV);
function stopWhenExceedOneV(src, event, ValueFromWorkspace)
if any(event.Data > 1.0*ValueFromWorkspace)
disp('Event listener: Detected voltage exceeds 1, stopping acquisition')
% Continuous acquisitions need to be stopped explicitly.
src.stop()
plot(event.TimeStamps, event.Data)
else
disp('Event listener: Continuing to acquire')
end
end
In this example the ValueFromWorkspace is a variable I would like to pull in from my workspace. Regards, J
Respuestas (1)
Walter Roberson
el 25 de Ag. de 2015
If ValueFromWorkspace changes over time and you need the newest version:
Define stopWhenExceedOneV as a nested function in the workspace that defines ValueFromWorkspace, and the definition must be after ValueFromWorkspace is initialized in the outer function. You would not have ValueFromWorkspace as one of the parameters of stopWhenExceedOneV
However, if ValueFromWorkspace is constant then leave your function as it is add use
lh = addlistener(s,'DataAvailable', @(src,event) stopWhenExceedOneV(src, event, ValueFromWorkspace));
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!