Assemble of a vector into a matrix
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Guillaume
am 18 Dez. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!