Place string in front of vector

1 次查看(过去 30 天)
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) ']']

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by