Assemble of a vector into a matrix

조회 수: 5 (최근 30일)
Ermin Sehovic
Ermin Sehovic 2015년 12월 18일
답변: Guillaume 2015년 12월 18일
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.

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by