How do I use arrayfun with inputs of arrays and scalar constants

2 次查看(过去 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

回答(1 个)

Walter Roberson
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
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by