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 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