How can I get my feature name from the location of matrix?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
2017-5-3
6 个评论
Walter Roberson
2017-5-4
non_nan = find(~isnan(scores));
[sorted_score, sort_idx] = sort( scores(non_nan) );
p = text2( non_nan(sort_idx) );
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!