gpuArray loop indexing question
조회 수: 1 (최근 30일)
For those familiar with gpuArray and arrayfun, is there a way to perform the following operation?
The general form is:
Much thanks in advance!
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);