Place string in front of vector

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 commentaire

Matt J
Matt J le 26 Oct 2012
Modifié(e) : Matt J le 26 Oct 2012
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.

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 26 Oct 2012

0 votes

result = arrayfun(@(i) ['B',num2str(i)] , num , 'uni',0);

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 26 Oct 2012
Modifié(e) : Azzi Abdelmalek le 26 Oct 2012

1 vote

[ '[' sprintf('B%d ',1:16) ']']

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by