How to form a feature vector from text file?
2 views (last 30 days)
Show older comments
ai ping Ng
on 11 Mar 2017
Edited: Walter Roberson
on 12 Mar 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
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
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!