Construct this matrix based on two vectors MATLAB

前端 未结 3 399
花落未央
花落未央 2021-01-22 02:22

I do have 2 vectors and i want to construct a matrix based onr and c

r =

 1
 2
 4
 6
 8

c =

 2
 4
 6
 8
10
         


        
3条回答
  •  半阙折子戏
    2021-01-22 02:41

    You could use the constructor for sparse matrices:

    full(sparse(r,c,1))
    

    by the way, if you want to apply this to large matrices with many zeros, stay with the sparse one. It uses much less memory for matrices with many zeros:

    sparse(r,c,1)
    

提交回复
热议问题