In MATLAB, I’d like to apply a function to every pair of column vectors in matrices A and B. I know there must be an efficient (non for) way of doing this, but I can’t figure it out. The function will output a scalar.
In MATLAB, I’d like to apply a function to every pair of column vectors
Share
Try
bsxfunperforms singleton expansion on 1:na and (1:nb)’. The end result, in this case, is that func will be applied to every pair of column vectors drawn from A and B.Note that bsxfun can be tricky: it can require that the applied function support singleton expansion itself. In this case it will work to do the job you want.