Assemble of a vector into a matrix

4 vues (au cours des 30 derniers jours)
Ermin Sehovic
Ermin Sehovic le 18 Déc 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.

Réponses (1)

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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by