MATLAB: Comparing two strings with Database

strcmpi

Hi.
I have a DataBase(DB1) and i need to find "family" AND "work" in it.(Not OR).
my code is :
DB1 = {'family','city','May','30','(AFP)','work','US','prosecutors',… 'on','Friday','unveiled','a','14-count','indictment',… 'including','charges','of','murder','and','loan','sharking','against',… 'body','demands'};
count=0;
for p=1:size((DB1))
if strcmpi(DB1{p}, 'family') && strcmpi(DB1{p}, 'work')
fprintf('\n Found ')
count=count+1;
copyfile(file_name,des_file_addr)
end
end
p=p+1;
fprintf('\n count= %g',count)
fprintf('\n -----------------------' )
My code doesn't show True Result(it shows "count =0" , But True Result("count") must be 1), can anyone help me?

Best Answer

Hi,
just guessing: your DB1 is one row of your database? And you are looking for rows, in which you find both an occurrence of work and family? In this case I guess you would write
match = all(ismember({'work', 'family'}, DB1));
And if it's indeed only an example, and your DB1 would be a NxM cell array, the match would be
for i=1:size(p,1)
match_i = all(ismember({'work', 'family'}, DB1(p,:)));
end
Titus
Related Question