MATLAB: How to run 2 tasks in parallel

data acquisitionMATLABparallel computing

I have 2 scripts.
Script1.m___________%infinite while loop which constantly modifying a 'fixed length array'
Script2.m___________% again infinite loop which is processing a live video.
Script1 is independent. But script2 requires the fixed length array generated by script1 before starting image processing on each frame.
I can't merge the scripts because time taken by image processing is significant and will modify script1's independency.
Any alternate non-conventional ideas are also welcome.
Thanks

Best Answer

You could use two timer objects, one for updating your s vector, and another for extracting the s vector and processing the image with it. See example code and modify the functions script1 and script2.
BUT, this isn't truely in parallel... The real solution require some sort of talk between workers and parallel. See this
%createTimer1.m---------------------------------
function Timer1 = createTimer1()
UserData.s = zeros(1, 100);
UserData.i = 1;
UserData.n = 100;
Timer1 = timer;
Timer1.UserData = UserData;
Timer1.Period = 0.01;
Timer1.TasksToExecute = Inf; %replaces your infinite while loop
Timer1.ExecutionMode = 'fixedSpacing';
Timer1.Timerfcn = @script1;
function script1(Timer1, events)
UserData = get(Timer1, 'UserData');
UserData.s = [UserData.s(2:end) UserData.i];
UserData.i = UserData.i + 1;
set(Timer1, 'UserData', UserData);
%-----------------------------------------------------end of createTimer1.m
%createTimer2.m---------------------------------
function Timer2 = createTimer2(Timer1)
Timer2 = timer;
Timer2.UserData = Timer1;
Timer2.Period = 0.01;
Timer2.TasksToExecute = Inf;
Timer2.ExecutionMode = 'fixedSpacing';
Timer2.Timerfcn = @script2;
function script2(Timer2, events)
UserData = get(get(Timer2, 'UserData'), 'UserData'); %get Timer1's current data
disp(UserData.s); %to show you what's happening
%-----------------------------------------------------end of createTimer2.m
To run these, use the script:
Timer1 = createTimer1();
Timer2 = createTimer2(Timer1);
start(Timer1);
start(Timer2);