how do i slice a variable in parfor?

1 次查看(过去 30 天)
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.

采纳的回答

Matt J
Matt J 2015-1-24
编辑:Matt J 2015-1-24
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 个评论
Matt J
Matt J 2015-1-24
编辑:Matt J 2015-1-24
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 2015-1-25
Thanks @matt... could you please see my other question here getappdata-setappadata

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by