Insert a string section on the numbers in a vector

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]

 Accepted Answer

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

3 Comments

More efficient with sprintf:
fun = @(x)sprintf('CH_%u',x);
res = arrayfun(fun, A, 'UniformOutput', false);

Sign in to comment.

More Answers (1)

A = [ 2 7 9 13];
str = sprintf('CH_%d ',A);
CH_2 CH_7 CH_9 CH_13

Categories

Find more on Text Analytics Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!