How can I input a vector into a sparse matrix instead of a single number?
1 view (last 30 days)
Show older comments
Hello,
I'm trying to form a matrix of the form:
[1 1 0 0 0 0 0 0; 0 0 1 1 0 0 0 0; 0 0 0 0 1 1 0 0; 0 0 0 0 0 0 1 1]
using the sparse function. I'm able to get the first diagonal of ones (i.e. [1 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 0; 0 0 0 0 1 0 0 0; 0 0 0 0 0 0 1 0]
using x=1:4 y=1:2:8 mat=sparse(x,y,1,4,8).
What I figured I could do would be to define a=[1,1] and do mat=sparse(x,y,a,4,8)
but matlab doesn't like that I'm trying to give a vector of a difference length from x and y to the spot (and I don't want it to be the same length as x and y, because then it just makes the matrix I can already make by just putting a 1 instead of a).
Does anyone know how to work around this?
Thanks!
-Libby
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!