Borrar filtros
Borrar filtros

Vector from character array

4 visualizaciones (últimos 30 días)
MarshallSc el 2 de Ag. de 2021
Editada: DGM el 2 de Ag. de 2021
If I have a character array for example:
I want to introduce a vector for example B in which if the it says 'high' in A I would have 1 and 0 for the ones that are 'low', something like:
How can I do that? Thanks in advance.

Respuesta aceptada

DGM el 2 de Ag. de 2021
Editada: DGM el 2 de Ag. de 2021
Something like this
A = {'high','low','low'};
B = strcmp(A,'high')
B = 1×3 logical array
1 0 0
Bear in mind that this only tests whether elements of A contain 'high'. It's implied that the only possible contents are 'high' and 'low', so that should be sufficient. If it's not, then we need to ask how other inputs should be represented.

Más respuestas (0)


Más información sobre Matrix Indexing en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by