Filling cells with repetitive strings

31 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2017 年 1 月 24 日
回答済み: Jan 2017 年 1 月 24 日
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

回答 (3 件)

Walter Roberson
Walter Roberson 2017 年 1 月 24 日
https://www.mathworks.com/help/matlab/ref/repelem.html
Works on cells too.
  2 件のコメント
MiauMiau
MiauMiau 2017 年 1 月 24 日
But I would like to have something along the lines of
x{1:10} = repelem('hello',10,1)
so x{1} should contain 'hello', then x{2} as well etc. That doesn't seem to work..?
Walter Roberson
Walter Roberson 2017 年 1 月 24 日
x = repelem( {'hello','tree'}, [10,10])
Or
x(1:10) = {'hello'};

サインインしてコメントする。


Purushottama Rao
Purushottama Rao 2017 年 1 月 24 日
a=cell(1,60);
a(1,1:10)={'hello'};
a(1,11:20)={'tree'};
etc...

Jan
Jan 2017 年 1 月 24 日
Strings = {'hello', 'tree', 'third', 'fifth', 'sixth'};
C = reshape(repmat(Strings, 10, 1), 1, []);

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by