Vectorized exponentiation

前端 未结 2 1317
执念已碎
执念已碎 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 13:51

    This is probably a bit sloppier than the bsxfun answer, but you could use meshgrid:

    E = X.^(meshgrid(N)')
    

    This assumes both X and N are row vectors. If both are column vectors then it becomes:

    E = X.^(meshgrid(N))
    

提交回复
热议问题