MATLAB: Run two functions (M.file) simultaneously and make them communicate with each other

parallel computing

I have got two methods to solve one time-consuming problem, each method will give the final answer iteratively. These two methods are coded as two functions (M.file) by Matlab. Can I make these two functions run together using Matlab? And once a method got a new result during the iterative process, Is it possible to share the result with the other method to improve its efficiency? Many thanks in advance.

Best Answer

The easiest way to do that is to Parallel Computing Toolbox with the spmd directive with two lab (workers). You would use a structure such as
if labindex == 1
first_function()
else
second_function();
end
The code to be executed can send information to the other side using labSend() and receive inormation using labReceive()
This is not the only approach, but this is the one that matches your requirements most closely.