Borrar filtros
Borrar filtros

Insert a string section on the numbers in a vector

1 visualización (últimos 30 días)
HERBERT NYAKOOJO
HERBERT NYAKOOJO el 21 de Feb. de 2020
Comentada: HERBERT NYAKOOJO el 21 de Feb. de 2020
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]

Respuesta aceptada

Bhaskar R
Bhaskar R el 21 de Feb. de 2020
res = arrayfun(@(x)strcat('CH_', num2str(x)), A, 'UniformOutput', false);
res{1}, res{2} % to get each element
  3 comentarios
Stephen23
Stephen23 el 21 de Feb. de 2020
More efficient with sprintf:
fun = @(x)sprintf('CH_%u',x);
res = arrayfun(fun, A, 'UniformOutput', false);
HERBERT NYAKOOJO
HERBERT NYAKOOJO el 21 de Feb. de 2020
Perfect man
Thank you

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by