implicit expansion for arrayfun
4 次查看(过去 30 天)
显示 更早的评论
I want to do something similar to bsxfun, but for more than 2 arrays. For example
arrayfun(@f, A,B,C,D)
where A is a m-by-n matrix, B is a scalar, C is a m-by-1 vector, D is a 1-by-n vector. Right now arrayfun would just throw an error.
I wonder if there is something that could first check whether they are compatible, and then apply repmat so that they all become m-by-n. I couldn't find anything, but hopefully someone is better at this.
Edit:
It appears that arrayfun will do this when input is a gpuArray
"B = arrayfun(FUN,A1,...,An) applies FUN to the elements of the arrays A1,...,An, so that B(i,j,...) = FUN(A1(i,j,...),...,An(i,j,...)).The function FUN must take n input arguments and return a scalar. The nonsingleton dimensions of the inputs A1,...,An must all match, or the inputs must be scalar. Any singleton dimensions or scalar inputs are virtually replicated before being input to the function FUN."
I will dig more into this.
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!