Assemble of a vector into a matrix
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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{:})
0 Comments
See Also
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!