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.
0 件のコメント
採用された回答
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
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!