Filter löschen
Filter löschen

Place string in front of vector

1 Ansicht (letzte 30 Tage)
Quy
Quy am 26 Okt. 2012
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 Kommentar
Matt J
Matt J am 26 Okt. 2012
Bearbeitet: Matt J am 26 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 26 Okt. 2012
result = arrayfun(@(i) ['B',num2str(i)] , num , 'uni',0);

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 26 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 26 Okt. 2012
[ '[' sprintf('B%d ',1:16) ']']

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by