How to form a feature vector from text file?

2 visualizaciones (últimos 30 días)
ai ping Ng
ai ping Ng el 11 de Mzo. de 2017
Editada: Walter Roberson el 12 de Mzo. de 2017
Hi, hope anyone can help me, truly appreciated. I have 10 features inside my text file ('Dataset1_Permission.txt') and its' row by row. What I wanted is, if my AndroidManifest.txt exist this feature then output as 1, if not output as 0. So, let say I only have 1 feature inside my Dataset1_Permission.txt file, It should output like..
0010000000
text = fileread('AndroidManifest.txt'); % read input manifest file
text2 = fileread('Dataset1_Permission.txt'); % read android permission list dataset
matchStr = regexpi(text,'\"android.permission.\w*\"','match') %extract the keyword in manifest file

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Mzo. de 2017
Editada: Walter Roberson el 12 de Mzo. de 2017
text1 = fileread('AndroidManifest.txt'); % read input manifest file
text2 = regexp(fileread('Dataset1_Permission.txt'), '\r?\n', 'split'); % read android permission list dataset
features = ~cellfun(@isempty,regexp(text1,text2));
  2 comentarios
ai ping Ng
ai ping Ng el 12 de Mzo. de 2017
I get this error message, when I have multiple features exist in my dataset.What shouldI do for the next?
Multiple strings and patterns given must have the same quantity
Walter Roberson
Walter Roberson el 12 de Mzo. de 2017
Editada: Walter Roberson el 12 de Mzo. de 2017
I have corrected the code. I made a typing mistake when I was changing your variable "text" to something else to avoid conflict with the important MATLAB plotting routine text().
Note: this code assumes that the first input to regexp() is a single string, not a cell array of strings. The error message you got would occur if you tried to use a cell array of strings.
If you have a cell array of strings to test, then you need to define whether you want one feature vector per cell member, or if you want the feature vector to reflect whether the substrings occur in any of the cell members.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings 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