本文介绍了基于两个向量MATLAB构造此矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确实有2个向量,我想基于r和c构造一个矩阵
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
我想构造一个矩阵A使得A(1,2)= A(2,4)= A(4,6)= A(6,8)= A(8,10)= 1其他元素0.
i want to construct a matrix A such that A(1,2)=A(2,4)=A(4,6)=A(6,8)=A(8,10)=1 other elements 0.
请帮助
推荐答案
您可以将构造函数用于稀疏矩阵:
You could use the constructor for sparse matrices:
full(sparse(r,c,1))
顺便说一句,
,如果要将其应用于具有多个零的大型矩阵,请保留稀疏的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)
这篇关于基于两个向量MATLAB构造此矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!