フィルターのクリア

Place string in front of vector

1 回表示 (過去 30 日間)
Quy
Quy 2012 年 10 月 26 日
I have a vector of numbers: num = [1:16]; I would like to place the character: 'B' in front of each number i that vector without using the for loop.
Are there any tricks to do this quickly?
The result should look like this:
[B1 B2 B3 B4........]
thanks.
  1 件のコメント
Matt J
Matt J 2012 年 10 月 26 日
編集済み: Matt J 2012 年 10 月 26 日
I hope you're not trying to use EVAL to create separate variables with auto-generated names B1, B2,... That is a Notoriously Bad Thing To Do.

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

採用された回答

Matt J
Matt J 2012 年 10 月 26 日
result = arrayfun(@(i) ['B',num2str(i)] , num , 'uni',0);

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 26 日
編集済み: Azzi Abdelmalek 2012 年 10 月 26 日
[ '[' sprintf('B%d ',1:16) ']']
  1 件のコメント
Matt Fig
Matt Fig 2012 年 10 月 26 日
+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