A column vector with words

I am trying to get an SVM working, for that i need a column vecotor of lables. My first attempt resulted in the input of 'F' and 'H' being turned into numbers (this is the only thing that would not result in an error message.
I want a colum of words, names 'Friendly' and 'Hostile'
The simplified version of what I've got:
>> A=zeros(10,1);
>> A(1:5)='F';
>> A(6:10)='H';
>> A
A =
70
70
70
70
70
72
72
72
72
72

Respuestas (1)

Cris LaPierre
Cris LaPierre el 9 de Abr. de 2021
Editada: Cris LaPierre el 9 de Abr. de 2021
All values in your variable must be of the same datatype. By creating your variable with the zeros function, you define A as being of type double, When you add a 'F' and 'H' to A, you are getting the ascii character code for those letters.
If you want to store letters or words, then your variable must be of type char or string.
A=strings(10,1);
A(1:5)='F';
A(6:10)='H'
A = 10×1 string array
"F" "F" "F" "F" "F" "H" "H" "H" "H" "H"

Etiquetas

Preguntada:

el 9 de Abr. de 2021

Editada:

el 9 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by