How can I get my feature name from the location of matrix?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ai ping Ng
le 20 Mar 2017
Commenté : ai ping Ng
le 5 Mai 2017
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
0 commentaires
Réponse acceptée
Walter Roberson
le 21 Mar 2017
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.
Plus de réponses (1)
ai ping Ng
le 3 Mai 2017
6 commentaires
Walter Roberson
le 4 Mai 2017
non_nan = find(~isnan(scores));
[sorted_score, sort_idx] = sort( scores(non_nan) );
p = text2( non_nan(sort_idx) );
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!