cell operation

2 次查看(过去 30 天)
zhang
zhang 2011-12-28
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
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)));

类别

Help CenterFile 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