cell operation

2 Ansichten (letzte 30 Tage)
zhang
zhang am 28 Dez. 2011
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

Akzeptierte Antwort

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

Weitere Antworten (1)

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by