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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Mzo. de 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.
  1 comentario
ai ping Ng
ai ping Ng el 21 de Mzo. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (1)

ai ping Ng
ai ping Ng el 3 de Mayo de 2017
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 comentarios
Walter Roberson
Walter Roberson el 4 de Mayo de 2017
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 el 5 de Mayo de 2017
Thanks, work well.

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by