Borrar filtros
Borrar filtros

Convert numerical label Vector to char label

3 visualizaciones (últimos 30 días)
benghenia aek
benghenia aek el 4 de Jun. de 2022
Editada: Star Strider el 4 de Jun. de 2022
Hello,I want to convert a to b please a=[1 1 2 1 3 1 3 2] To b=[as as be as ce as ce be].

Respuesta aceptada

Star Strider
Star Strider el 4 de Jun. de 2022
Editada: Star Strider el 4 de Jun. de 2022
Try this —
map = {'as','be','ce'}; % Cell Array
a=[1 1 2 1 3 1 3 2];
b = map(a)
b = 1×8 cell array
{'as'} {'as'} {'be'} {'as'} {'ce'} {'as'} {'ce'} {'be'}
b = strtrim(sprintf(' %s ',b{:}))
b = 'as as be as ce as ce be'
% To b=[as as be as ce as ce be].
map = ["as","be","ce"]; % String Array
a=[1 1 2 1 3 1 3 2];
b = map(a)
b = 1×8 string array
"as" "as" "be" "as" "ce" "as" "ce" "be"
b = strtrim(sprintf(' %s ',b))
b = 'as as be as ce as ce be'
EDIT — (4 Jun 2022 at 2:48)
Added sprintf and strtrim calls.
.

Más respuestas (0)

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