Filling cells with repetitive strings
39 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
I want to create a 1x60 cell array (60 different elements). The elements 1:10 each should contain a certain string, say 'hello', then 11:20 should contain say 'tree' etc. How do I do this effectively? Currently I am using different loops for each string, but that seems not to be very effective..thanks
0 Commenti
Risposte (3)
Walter Roberson
il 24 Gen 2017
https://www.mathworks.com/help/matlab/ref/repelem.html
Works on cells too.
2 Commenti
Walter Roberson
il 24 Gen 2017
x = repelem( {'hello','tree'}, [10,10])
Or
x(1:10) = {'hello'};
Purushottama Rao
il 24 Gen 2017
a=cell(1,60);
a(1,1:10)={'hello'};
a(1,11:20)={'tree'};
etc...
0 Commenti
Jan
il 24 Gen 2017
Strings = {'hello', 'tree', 'third', 'fifth', 'sixth'};
C = reshape(repmat(Strings, 10, 1), 1, []);
0 Commenti
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!