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

 Risposta accettata

Walter Roberson
Walter Roberson il 28 Dic 2011

2 voti

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

Più risposte (1)

Jan
Jan il 30 Dic 2011

0 voti

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

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by