Undefined function 'regexp' for input arguments of type 'struct'

조회 수: 11 (최근 30일)
ai ping Ng
ai ping Ng 2017년 3월 4일
댓글: Walter Roberson 2017년 3월 17일
I want to extract keywords(which the word start with import.XXXX) from multiple files under annotation folder. I run my code like this, Y I get the error? Anybody can help?
r = dir(fullfile('C:\Users\ASUS\Desktop\AngryBirdTest\android\support\annotation', '*.java'));
for i=1:length(r)
p = regexpi(FileList,'import.\w*.\w*.\w*','match');
disp(p(i));
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 3월 5일
Are those things stored inside the files or are they part of the file names?

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 5일
My guess:
projectdir = 'C:\Users\ASUS\Desktop\AngryBirdTest\android\support\annotation';
r = dir(fullfile(projectdir, '*.java'));
filenames = {r.name};
FileList = fullfile(projectdir, filenames);
for K = 1:length(FileList)
thisfile = FileList{K};
fprintf('\nExamining file "%s"\n', thisfile); %if desired
filecontent = fileread(thisfile);
p = regexpi(filecontent, 'import.\w*.\w*.\w*', 'match');
disp(p);
end
  댓글 수: 7
ai ping Ng
ai ping Ng 2017년 3월 17일
Thanks. Get it. I change into a string, it works.
r = dir(fullfile('C:\Users\ASUS\Desktop\FYP\M1\ClassFileTest/', '*.java'));
r2 = regexp(fileread('Dataset3_API.txt'), '\r?\n', 'split');
saveValueP = [];
for i=1:length(r)
p = regexp(fileread(strcat('C:\Users\ASUS\Desktop\FYP\M1\ClassFileTest/',r(i).name)), 'import android.\w*.\w*.\w*','match');
saveValueP = [saveValueP p];
no_duplicates = unique(saveValueP); %remove duplicated features
end
str = strjoin(no_duplicates);
features3 = ~cellfun(@isempty,regexp(str,r2,'match'));
disp(no_duplicates)
I still meet a question after that. Let say now I am examining the Class file which under M1 folder >> 'C:\Users\ASUS\Desktop\FYP\M1\ClassFileTest/' How if I have 'M1 folder' 'M2 folder' and 'M3 folder' ... 'Mx folder' to undergo? Is that a way to make it automatically examine and then can produce all of my folders' feature vectors?
Walter Roberson
Walter Roberson 2017년 3월 17일
https://www.mathworks.com/matlabcentral/answers/57446-faq-how-can-i-process-a-sequence-of-files

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

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 3월 5일
You didn't show us how you got FileList. Evidently it thinks it's a structure.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by