how to optimize a diag matrix with sparse

How to optimize this diagonal matrix using sparse :
a=diag([-ones(9,1)],-1)+diag([ones(10,1)])+diag([0 ones(1,4) 0],4)

Answers (1)

If you mean how to create the equivalent sparse matrix to your full matrix shown, try using the spdiags function instead of diag.

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Asked:

on 5 Jun 2014

Answered:

on 5 Jun 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!