A matrix operation in MATLAB

前端 未结 1 585
粉色の甜心
粉色の甜心 2021-01-21 15:18

I am trying to simplify my code a bit, and I am across a small question. Let

v  = [1; 2; 3];
a1 = [4; 5; 6];
a2 = [7; 8; 9];
A  = [a1, a2];

I

相关标签:
1条回答
  • 2021-01-21 15:34

    yes, you can do this using bsxfun, for example:

    u = bsxfun(@times,A,v);
    

    or also by using repmat

    u= repmat(v,[1 2]).*A;
    

    or also by using kron

    u= kron(v,[1 1]).*A;
    

    or last, just using matrix multiplication:

    u = v*[1 1].*A;
    

    I'm sure there are even more ways, but I'll stop here...

    0 讨论(0)
提交回复
热议问题