There is a cell array. A = {'ab', 'bc', 'cd'};
I'd like to get a new cell array, like: B = {'ab', 'ab', 'ab', 'bc', 'bc', 'bc', 'cd', 'cd', 'cd'}.
How to get this without using loop?
Thanks

 採用された回答

Walter Roberson
Walter Roberson 2011 年 12 月 28 日

2 投票

B = repmat(A, 3, 1); %do the duplication
B = B(:).' ; turn the result in to a row vector

その他の回答 (1 件)

Jan
Jan 2011 年 12 月 30 日

0 投票

A = {'ab', 'bc', 'cd'};
B = A(kron(1:3, ones(1,3)));

カテゴリ

ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by