How to run two parallel processes independently but with linked variables?

while i<100000,
A (i) = sin(2*i);
if (i< 100000),
disp(A(i));
pause(0.01);
end
i = i+1;
end
Here, the computation of A(i) has to be stopped for a period of 0.01 sec due to if loop. I want to keep computing the A(i) irrespective of the pause(0.01), but still display current A(i) value at a fixed interval of 0.01sec. Its like two parallel process, but one process need to access the variable of other process. How to achieve this?

Answers (1)

You can use spmd. In one lab compute the values, and use labsend() to send them to another process, which displays them at the desired rate.

1 Comment

Hi, I tried this script but, still there is a pause.
i = 1;
spmd (2)
while i<100,
if (labindex == 1)
A (i) = sin(2*i);
labSend(A(i),2);
i = i+1;
end
if (labindex == 2)
data = labReceive(1);
disp(data);
pause(0.1);
end
end
end

Sign in to comment.

Categories

Asked:

on 3 Oct 2015

Commented:

on 15 Oct 2015

Community Treasure Hunt

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

Start Hunting!