Convert Strings into vectors of binary numbers

5 visualizaciones (últimos 30 días)
Sam
Sam el 25 de En. de 2013
I need to convert utterance strings into vectors where each dimension of the vector represents a unique word, while reading the script from an m.file. So for example if I have, out='hello' 'my' 'name' 'is' 'sam'. I want a vector with binary numbers where hello is true and everything else is false.
Solution would be output=[1,0,0,0] How can I do this? Here is what I have so far
fid=fopen('sw4325.m')
>> firstline=fgets(fid);
>> sprintf(firstline);
>> splitstring=textscan(ans, '%s');
>> out=splitstring{:};

Respuesta aceptada

Jan
Jan el 25 de En. de 2013
I do not get it. Do you want STRCMP?
str = {'hello' 'my' 'name' 'is' 'sam'};
match = strcmp('hello', str);
  5 comentarios
Jan
Jan el 28 de En. de 2013
Sorry, I do not understand which data are strings and which are cell strings. Using ans directly is prone to errors. Better split the string explicitly, e.g. out = regexp(firstline, ' ', 'split'). And then please explain again the type of the inputs. Either strcmp or ismember should solve the problem.
Samira
Samira el 28 de En. de 2013
Yes it works, thank you so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing 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