How to form a feature vector from text file?

조회 수: 2 (최근 30일)
ai ping Ng
ai ping Ng 2017년 3월 11일
편집: Walter Roberson 2017년 3월 12일
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 11일
편집: Walter Roberson 2017년 3월 12일
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
ai ping Ng
ai ping Ng 2017년 3월 12일
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 2017년 3월 12일
편집: Walter Roberson 2017년 3월 12일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by