As I said, if you know how to do it in matlab for any data, you then use the same method. For instance n = 3;sparse(kron([1:n],[1 1]),[1:n],a)) would be a start for the first block if you want to make it general and avoid manually setting up the structure etc