How can I get my feature name from the location of matrix?

조회 수: 2 (최근 30일)
ai ping Ng
ai ping Ng 2017년 3월 20일
댓글: ai ping Ng 2017년 5월 5일
I have 3 input manifest files, each has 137 different features name to examine which save in 'Dataset1_Permission.txt'. If it exists in the files, it is 1, if not, will be 0. I will use the 137X3 logical vector to perform some calculation as I need to find the top 10 feature names in both 3 files. Now, I have sum each feature row by row and sort them to find the top 10 maximum features that exist in both 3 files. I can find the top 10 and retrieve the location of matrix but how can I get the features name of it? I can't figure out how to do so. Below is my sample code:
function [features1] = permission(~)
for app=1:3
text1 = fileread(sprintf('C:/Users/ASUS/Desktop/FYP/B%d/AndroidManifest.xml',app)); % read input manifest file
text2 = regexp(fileread('Dataset1_Permission.txt'), '\r?\n', 'split'); % read android permission list dataset
saveValue1 = [];
matchStr = regexp(text1,'\"android.permission.\w*\"','match'); %extract the keyword in manifest file
saveValue1 = [saveValue1 matchStr];
no_duplicates1 = unique(saveValue1);
str1 = strjoin(no_duplicates1);
features1{app} = ~cellfun(@isempty,regexp(str1,text2));
disp(no_duplicates1);
end
for app=1:length(features1)
features1{app}=features1{app}';
end
features1 = cell2mat(features1);
total =sum(features1,2);
[max_sorted,max_located] = sort( total, 'descend' );
n = max_sorted(1:10);
p = max_located(1:10);
disp(n)
disp(p)
end

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 21일
text2(p)
By the way, I would appreciate it if you stopped doing those strcat and switched to having a variable holding the directory name, and using fullfile(). Repeating the location construction like you are is error prone. It is also not at all portable. If you were to give the code to anyone else (like us volunteers) they would first have to spend their time searching the code and editing the location information repeatedly to match their own directory names. For example I cannot just change the username ASUS in multiple places because I do not run on MS Windows.
I already showed you the code to fix this issue... More than once.
  댓글 수: 1
ai ping Ng
ai ping Ng 2017년 3월 21일
Really appreciate your help, and so sorry for the inconvenience I have made. It is my fault that I didn't notice mine issue. This is my first year, first semester, I m still a newbie for coding. Thanks for advising me.

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

추가 답변 (1개)

ai ping Ng
ai ping Ng 2017년 5월 3일
After done for feature selection coding, I get my top 10 features also, but instead of getting integer numbers like before 1 4 7 90..., it gave me floating numbers 0.3033 0.2899 0.1277 0.0011..... So now, when I used text2(p), it came out the error as 'Subscript indices must either be real positive integers or logicals.' What can I do now to get back my feature name of it?
  댓글 수: 6
Walter Roberson
Walter Roberson 2017년 5월 4일
non_nan = find(~isnan(scores));
[sorted_score, sort_idx] = sort( scores(non_nan) );
p = text2( non_nan(sort_idx) );
ai ping Ng
ai ping Ng 2017년 5월 5일
Thanks, work well.

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by