The variable s in a parfor cannot be classified.
조회 수: 2 (최근 30일)
이전 댓글 표시
I would like to run the following code snippet in parallel as the size of the data is too huge.
data_no = 10099;
alpha = 0.5;
m = 1;
parfor i=1:data_no
parfor j=i+1:data_no
s1 = norm(data_corr(i,:)-data_corr(j,:));
s2 = norm(data(i,:)-data(j,:));
d = s1 + alpha*s2;
s(m,1) = i;
s(m,2) = j;
s(m,3) = -d;
m = m+1;
end
end
But I get the error "The variable s in a parfor cannot be classified". I have not had much luck with understanding the matlab help unfortunately.
Can somebody please help.
Thanks,
Janki
댓글 수: 0
채택된 답변
Matt J
2015년 1월 30일
Here is a method that avoids looping altogether. I expect it would be much faster than a parfor approach.
data_no=size(data_corr,1);
[I,J]=ndgrid(1:data_no);
idx=(J>I);
D=normMatrix(data_corr)+alpha*normMatrix(data);
s=[I(idx), J(idx), -D(idx)].';
function S=normMatrix(data)
normterms=sum(data.^2,2);
crossterms=data*data.';
S=bsxfun(@minus,normterms, 2*crossterms);
S=bsxfun(@plus,S,normterms.');
S=sqrt(S);
end
댓글 수: 2
참고 항목
카테고리
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!