cell operation

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

 采纳的回答

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

更多回答(1 个)

Jan
Jan 2011-12-30
A = {'ab', 'bc', 'cd'};
B = A(kron(1:3, ones(1,3)));

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by