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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Dic. de 2011

2 votos

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

Más respuestas (1)

Jan
Jan el 30 de Dic. de 2011

0 votos

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

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Dic. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by