Vectorized exponentiation

前端 未结 2 1319
执念已碎
执念已碎 2021-01-25 13:14

I have two vectors, X of bases and N of exponents. I want to get the matrix of all values e = xn for each x in

2条回答
  •  一向
    一向 (楼主)
    2021-01-25 14:03

    Use bsxfun:

    bsxfun(@power, X, N)
    

    This assumes that X is a column vector and N is a row vector. If you want to guarantee that, use the following syntax which is more robust:

    bsxfun(@power, X(:), N(:).')
    

提交回复
热议问题