implicit expansion for arrayfun
조회 수: 2 (최근 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!