Insert a string section on the numbers in a vector

1 visualizzazione (ultimi 30 giorni)
A = [ 2 7 9 13];
add text CH_ on each value in the vector A
output
B = [CH_2 CH_7 CH_9 CH_13]

Risposta accettata

Bhaskar R
Bhaskar R il 21 Feb 2020
res = arrayfun(@(x)strcat('CH_', num2str(x)), A, 'UniformOutput', false);
res{1}, res{2} % to get each element

Più risposte (1)

HERBERT NYAKOOJO
HERBERT NYAKOOJO il 21 Feb 2020
A = [ 2 7 9 13];
str = sprintf('CH_%d ',A);
CH_2 CH_7 CH_9 CH_13

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by