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

1 vue (au cours des 30 derniers jours)
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

Réponses (1)

Alvaro
Alvaro le 23 Jan 2023

Catégories

En savoir plus sur Startup and Shutdown 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