I would like to find a smarter way of building a larger matrix from vectors. The following code works fine:
rv = [1 2 3 4];alpha =[0.0140; 0.0100; 0.0100; 0.0100];c = [];for i = 1:4 c = [c; diag(alpha).*rv(i)];end>> c = 0.0140 0 0 0 0 0.0100 0 0 0 0 0.0100 0 0 0 0 0.0100 0.0280 0 0 0 0 0.0200 0 0 0 0 0.0200 0 0 0 0 0.0200 0.0420 0 0 0 0 0.0300 0 0 0 0 0.0300 0 0 0 0 0.0300 0.0560 0 0 0 0 0.0400 0 0 0 0 0.0400 0 0 0 0 0.0400
Essentially I build a submatrix from a vector. Then I multiple the diagonal submatrix with each element of a vector. Then I concatenate these vertically.
Is there a computationally more efficient way of doing this?
Thanks!
Best Answer