how do i slice a variable in parfor?

1 view (last 30 days)
Hi,
I am new to matlab, so I have this code here
function [ ] = test2()
h = EmotivEEG;
h.Run
parfor i = 1:5
data_local = h.data;
data_local = data_local+rand(1);
plot(data_local)
pause(0.5);
end
delete(h);
end
which h.run starts the function in EmotivEEG.m, delete(m) closes the connection to Emotiv.
I trued using parfor but i get "h variable is indexed but not sliced".
so data_local updates the plot every 0.5 seconds. What i wanted to do was to create a same loop and use its data some where else parallel.
I do have a parallel computing tool box could anyone tell me how to use parfor and matlabpool.

Accepted Answer

Matt J
Matt J on 24 Jan 2015
Edited: Matt J on 24 Jan 2015
What i wanted to do was to create a same loop and use its data some where else parallel.
And you want each parallel worker to use the entire data from h? If so, there's nothing wrong with the code as you've shown it.
The code analyzer warning is just telling you that this will result in h being copied and broadcast N times, where N is the number of workers. If the workers don't need all of the data from h, then there are ways to send only the pieces it needs, which reduces data copying and broadcast effort.
  3 Comments
Matt J
Matt J on 24 Jan 2015
Edited: Matt J on 24 Jan 2015
No, successive parfor loops are executed sequentially. Also, you won't be able to generate plots inside a parfor loop. The parfor workers don't have displays. But you can do things like this:
parfor ii = 1:5
data_local{i} = h.data + rand(1);
end
for i=1:5
figure(i);
plot(data_local{i})
end
akshay raj
akshay raj on 25 Jan 2015
Thanks @matt... could you please see my other question here getappdata-setappadata

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!