How to run .m files in one thread from an app running in a different thread so that I can interact with the app during .m file execution?
5 views (last 30 days)
I have an app that I have made programmatically (without appdesigner) that frequently calls already existing functions located in .m files when I click certain buttons. Currently, the app itself and the functions it calls are all run in the foreground. However, these functions can take a long time to execute (several hours), during which time I cannot interact with the app (because callbacks won't execute until after the functions finish running).
The documentation on backgroundPool and parfeval is a bit confusing to me. Is there a way to make the app run on one pool, and the functions in the .m files to run on another thread? I have access to the Parallel Computing Toolboox. Or, would it require running two instances of MATLAB simultaneously? Is it possible to share data across two instances of MATLAB?
Raymond Norris on 7 Sep 2022
@Mitchell Tillman you might consider refactoring the code so that the callbacks call parfeval with backgroundPool, but keep in the app running on MATLAB's main execution thread. For instance instead of
data = ..
% Spawn a thread to handle the plotting
% Come back immediately to free up the App
I'm leaving an awful lot out here, but hopefully you get the idea