Assemble of a vector into a matrix

2 views (last 30 days)
Ermin Sehovic
Ermin Sehovic on 18 Dec 2015
Answered: Guillaume on 18 Dec 2015
Which is the most effective way of assembling vector v into matrix A, such that matrix A is obtained? (Without using for loops).
v = [1;2;3;4;5;6;7;8;9],
What the assembly is supposed to look like:
A = [1;2;3;0;0;0;0;0;0 , 0;0;0;4;5;6;0;0;0 , 0;0;0;0;0;0;7;8;9].
Matrix A is a 9x3 matrix.

Answers (1)

Guillaume
Guillaume on 18 Dec 2015
v = [1;2;3;4;5;6;7;8;9];
vv = mat2cell(v, ones(numel(v)/3, 1) * 3, 1);
A = blkdiag(vv{:})

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!