How to form a feature vector from text file?

2 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 11 Mar 2017
Edited: Walter Roberson on 12 Mar 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 Comments
ai ping Ng
ai ping Ng on 12 Mar 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 on 12 Mar 2017
Edited: Walter Roberson on 12 Mar 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!