Stop an infinit function that is running in parallel with the remaining code, and get the outputs

1 次查看(过去 30 天)
Hello everyone,
I am looking for a way to retrieve the output of a function that is running in parallel (with the function parfeval for example) and that can run indefinitely if we don't stop it in the remaining code.
For example : This could be the function :
function a = infinit()
go = true ;
while go
a = 1 ;
end
end
and this is the code :
parpool(1) ;
f = parfeval(@infinit,1) ;
% looking for the code line that can stop the function,
value = fetchOutputs(f) ;
I know that "cancel" can actually stop, but then we can't get the output. I have also tryed by using a global variable, or a public variable with app designer, but both of those way are not working. From my research so far, it seems there is no solution. But still I hope that someone has maybe found an idea ! ;)
Otherwise, I actually want to run a function in app designer that is reading data from a sensor periodically. Meanwhile the code is doing something else until the user has finished the experiment. Then I want to get the data from the function. I guess maybe there might be a workaround ?
I thank you all in advance for your help !
Thomas

回答(1 个)

Alvaro
Alvaro 2023-1-23

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by