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

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 Comment

Are those things stored inside the files or are they part of the file names?

Sign in to comment.

 Accepted Answer

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 Comments

r = dir(fullfile('C:\Users\ASUS\Desktop\AngryBirdTest\API_ClassFileTest/', '*.java'));
for i=1:length(r)
p = regexp(fileread(strcat('C:\Users\ASUS\Desktop\AngryBirdTest\API_ClassFileTest/',r(i).name)), 'import android.\w*.\w*.\w*','match');
disp(p)
end
This is the final code I have figured out that day, thanks for your answer.I will use yr answer to learn it more.
But then why my workspace showing that my p have 0X0 cell only? How to show it in my workspace?
I need a sample file to test with.
I finally found out is because I didn't save it in matrix. I can output my p now after I save it in matrix form. Can I know how to output as a big feature vector like 000010000001.....01 like that? Mean if that feature exists, it shows as 1, if not it show it as 0. I use this "features3 = ~cellfun(@isempty,regexp(no_duplicates,r2));" but then it doesn't work. Below are my sample file and sample code. Hope you can help me, truly appreciated.
r = dir(fullfile('C:\Users\ASUS\Desktop\AngryBirdTest\API_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\AngryBirdTest\API_ClassFileTest/',r(i).name)), 'import android.\w*.\w*.\w*','match');
saveValueP = [saveValueP p];
no_duplicates = unique(saveValueP);
features3 = ~cellfun(@isempty,regexp(no_duplicates,r2));
end
disp(features3)
As I wrote before:
If you have a cell array of strings to test, then you need to define whether you want one feature vector per cell member, or if you want the feature vector to reflect whether the substrings occur in any of the cell members.
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?
https://www.mathworks.com/matlabcentral/answers/57446-faq-how-can-i-process-a-sequence-of-files

Sign in to comment.

More Answers (1)

You didn't show us how you got FileList. Evidently it thinks it's a structure.

Tags

Community Treasure Hunt

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

Start Hunting!