concatenating array using cellstr and repmat

1 回表示 (過去 30 日間)
Leor Greenberger
Leor Greenberger 2013 年 5 月 2 日
Hi All,
I have the following code
str = cellstr(char('This','Orthis'));
x = round(rand(10,1))+1;
output = [repmat('some text ',10,1) str{x}]
I want the output to look like:
output =
some text OrThis
some text This
some text This
etc..
where the last word in each row is selected by str{x}. This is not working, as the str{x} part of the concatenation is not generating the appropriate array. Any suggestions? Thanks!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 2 日
str = cellstr(char('This','Orthis'))
x = round(rand(10,1))+1
output = [repmat('some text ',10,1) char(str(x))]
  1 件のコメント
Leor Greenberger
Leor Greenberger 2013 年 5 月 2 日
That did it! Thanks!

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

その他の回答 (0 件)

カテゴリ

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