How do I use arrayfun with inputs of arrays and scalar constants
1 回表示 (過去 30 日間)
古いコメントを表示
I want to pass in both arrays and constants into my arrayfun but the error says that all inputs have to be the same size, however when I looked at this simulation http://www.mathworks.com/help/distcomp/examples/using-gpu-arrayfun-for-monte-carlo-simulations.html it is evident that not all inputs are the same size. This is my code
k=1
while k<row*column
ref_mu_pixel=ref_mu(k)*ones(1,row*column);
new_mu(k)= arrayfun(@gpurunloop,ref_mu_pixel,...
ref_mu,smooth_parameter,targ_mu);
k=k+1
end
where ref_mu,ref_mu_pixel,and targ_mu are vectors and smooth_parameter is a scalar constant
Thank you
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 1 月 22 日
I suspect that an exception is made for the case of scalar inputs. You have inputs that are vectors that are not the same size as your data, perhaps.
1 件のコメント
Edric Ellis
2016 年 1 月 22 日
編集済み: Edric Ellis
2016 年 1 月 22 日
That's correct - the gpuArray version of arrayfun allows singleton dimension expansion. This is mentioned in the reference page:
"Nonsingleton dimensions of input arrays must match each other. In other words, the corresponding dimensions of arguments B, C, etc., must be equal to each other, or equal to one. Whenever a dimension of an input array is singleton (equal to 1), arrayfun uses singleton expansion to virtually replicate the array along that dimension to match the largest of the other arrays in that dimension. In the case where a dimension of an input array is singleton and the corresponding dimension in another argument array is zero, arrayfun virtually diminishes the singleton dimension to 0."
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!