how do i slice a variable in parfor?

1 回表示 (過去 30 日間)
akshay raj
akshay raj 2015 年 1 月 24 日
コメント済み: akshay raj 2015 年 1 月 25 日
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 Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by