フィルターのクリア

gpuArray loop indexing question

2 ビュー (過去 30 日間)
tx213
tx213 2013 年 12 月 20 日
回答済み: Edric Ellis 2013 年 12 月 20 日
Hi guys,
For those familiar with gpuArray and arrayfun, is there a way to perform the following operation?
The general form is:
[a ,b]=find(phi)
PHI=zeros(---)
for n=1:numel(a)
PHI(a(n),b(n))=phi(a(n),b(n));
end
Much thanks in advance!

採用された回答

Edric Ellis
Edric Ellis 2013 年 12 月 20 日
I think part of your underlying problem must be missing here, since in this case, PHI and phi end up the same. Anyway, you could use logical indexing for this.
% generate 'phi' as a random matrix
phi = gpuArray.rand(100);
% set all elements <0.9 to zero
phi(phi < 0.9) = 0;
% pre-allocate PHI
PHI = gpuArray.zeros(size(phi));
% Instead of FIND, use 'logical' to get the places
% where phi is non-zero
match = logical(phi);
% Use logical indexing to copy the elements
PHI(match) = phi(match);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by