How can I output my answer automatically with different sub-folders?

조회 수: 1 (최근 30일)
ai ping Ng
ai ping Ng 2017년 3월 17일
댓글: Guillaume 2017년 3월 17일
Let say, now, I need to read AndroidManifest.xml, and I have n folders to undergo, namely M1, M2, M3... Mn. Is there a way to make it examine automatically? So my output will contain a feature vector from different folders.
Below is my sample code:
text1 = fileread('C:\Users\ASUS\Desktop\FYP\ *M1*\AndroidManifest.xml'); % read input manifest file
text2 = regexp(fileread('Dataset1_Permission.txt'), '\r?\n', 'split'); % read android permission list dataset
matchStr = regexp(text1,'\"android.permission.\w*\"','match'); %extract the keyword in manifest file
features1 = ~cellfun(@isempty,regexp(text1,text2));
disp(matchStr);
  댓글 수: 2
KSSV
KSSV 2017년 3월 17일
What is the problem now with your code? You have not mentioned it.
ai ping Ng
ai ping Ng 2017년 3월 17일
As stated above, I can't figure out how to output my answer when I have more than 1 folder to examine. Now it's fine since I only examine M1 folder only, but instead of manually changing my directory to M2, M3, and so on... is there a way to read it automatically by using Matlab?

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

채택된 답변

Rik
Rik 2017년 3월 17일
Have you tried a loop the filename formed with sprintf?
for folder_number=1:5
text1 = fileread(sprintf('C:\Users\ASUS\Desktop\FYP\M%d\AndroidManifest.xml',folder_number)); % read input manifest file
text2 = regexp(fileread('Dataset1_Permission.txt'), '\r?\n', 'split'); % read android permission list dataset
matchStr = regexp(text1,'\"android.permission.\w*\"','match'); %extract the keyword in manifest file
features{folder_number} = ~cellfun(@isempty,regexp(text1,text2));
disp(matchStr);
end
I don't know what you would want to do with matchStr. (Note: if you have many folders, pre-allocating the features variable may be a good idea)
  댓글 수: 6
Rik
Rik 2017년 3월 17일
You mean something like
%answer = [1x137 logical] [1x137 logical] [1x137 logical]
for item=1:length(answer)
answer{item}=answer{item}';
end
answer = cell2mat(answer);
(just an off the cuff answer, plus I'm tired, so no guarantees)
Guillaume
Guillaume 2017년 3월 17일
Note: the reason for the Warning: Control Character '\U' is not valid is because the '\' used as path separator here has special meaning in sprintf. It introduces control characters. If you want the '\' to be interpreted as such, you need to escape it by doubling it.
sprintf('C:\\Users\\ASUS\\Desktop\\FYP\\M%d\\AndroidManifest.xml')
would have worked. But as Rik said, Windows doesn't mind '/' as a path separator, so you may use that as well.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 3월 17일
https://www.mathworks.com/matlabcentral/answers/57446-faq-how-can-i-process-a-sequence-of-files

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by