How can I modify this code to use parfor s=1:r?

조회 수: 1 (최근 30일)
MRC
MRC 2013년 11월 1일
답변: Edric Ellis 2013년 11월 4일
Hi, I have reported here a very simple piece of code but it basically faces the same issues of my actual estimation code. Could you help me in modifying it to use parfor s=1:r? Thanks a lot!
r=20;
n=2;
m=3;
D=unidrnd(20,8,2);
upp=zeros(size(D,1),r,n);
for j=1:n
A=unidrnd(10,m,n);
parfor s=1:r
B=unidrnd(10,m,n);
C=A+B;
for i=1:size(C,1)
for w=1:size(D,1)
if all(C(i,:)==D(w,:))
upp(w,s,j)=1;
end
end
end
end
end

채택된 답변

Edric Ellis
Edric Ellis 2013년 11월 4일
You could try something like this
r=20;
n=2;
m=3;
D=unidrnd(20,8,2);
upp=zeros(size(D,1),r,n);
for j=1:n
A=unidrnd(10,m,n);
parfor s=1:r
B=unidrnd(10,m,n);
C=A+B;
% Make a temporary vector to build up in the FOR loops below
tmp = zeros(1, size(D,1));
for i=1:size(C,1)
for w=1:size(D,1)
if all(C(i,:)==D(w,:))
% Assign an element of 'tmp'
tmp(w) = 1;
end
end
end
% Assign all of 'tmp' into 'upp'.
upp(:, s, j) = tmp;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by