"Kronecker" of varying dimensions?

1 回表示 (過去 30 日間)
MRC
MRC 2013 年 11 月 27 日
編集済み: Azzi Abdelmalek 2013 年 11 月 27 日
Hi, I have a matrix A of dimension m x n and a vector b of natural numbers with dimension m x 1. I want to obtain a matrix C of dimension (b(1)+...+b(m)) x n by vertically stacking each A(i,:) b(i) times. For example:
A=[1 2 3; 4 5 6; 7 8 9];
b=[2; 1; 4];
I want to obtain
C=[1 2 3; 1 2 3; 4 5 6; 7 8 9; 7 8 9; 7 8 9; 7 8 9];
I cannot use loops.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 27 日
編集済み: Azzi Abdelmalek 2013 年 11 月 27 日
A=[1 2 3; 4 5 6; 7 8 9]
b=[2; 1; 4]
out=cell2mat(arrayfun(@(x) repmat(A(x,:),b(x),1),(1:size(A,1))','un',0))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by