matrix index in Parfor loop

1 回表示 (過去 30 日間)
rahman
rahman 2015 年 1 月 25 日
編集済み: Matt J 2015 年 1 月 25 日
Hi all. for code I write below, I want to use Parfor but MATLAB report an Error for definition t(s):ts(s)+a as the index of matrix b. Does anyone have any Idea help me ?
for s=1:e
b( s, t(s):ts(s)+a ) = ...
end

回答 (1 件)

Matt J
Matt J 2015 年 1 月 25 日
編集済み: Matt J 2015 年 1 月 25 日
You must first pre-align the data vectors b( s, t(s):ts(s)+a ) into the columns of a matrix B. That way, parfor can see that the data pieces are parallel across s and can slice them,
t=t(:).'; %row
s=(1:e);
T=bsxfun(@plus, t(1:e),(0:a).');
S=repmat((1:e),a+1,1);
idx=sub2ind(size(b), S,T);
B=b(idx);
parfor s=1:e
B(:,s)= ...
end
b(idx)=B;

カテゴリ

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