Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Good way to compare two cell arrays???

5 views
Skip to first unread message

Darin

unread,
Sep 2, 2010, 5:49:04 PM9/2/10
to
Hello,

Your advice is needed to help figure out an eloquent solution to compare two cell arrays (that contain strings). The first cell array (files) needs to be shrunk down whenever it exists in the second array (finishedfiles). The final shrunken down array is called newfiles. Is there a better way to do this???

count2= 0;
for i = 1:numel(files)

count = 0;
for j = 1:numel(finishedfiles)
if strcmp(files{i},finishedfiles{j})
count=1;
break;
end
end

if count == 0;
count2 = count2+1;
newfiles{count2} = files{i};
end

end

TideMan

unread,
Sep 2, 2010, 6:54:01 PM9/2/10
to

help intersect

Roland

unread,
Sep 2, 2010, 7:30:21 PM9/2/10
to
"Darin " <dmc...@mail.bradley.edu> wrote in message <i5p64g$nsl$1...@fred.mathworks.com>...

not 100% sure, but i think this should do what you want

clc
clear all

files={'file1';'file2';'file3'};
finishedfiles={'file3';'file2'};

a=repmat(files,size(finishedfiles));
b=sort(repmat(finishedfiles,size(files)));

c=(strcmp(a,b));

d=reshape(c,size(files,1),size(c,1)/size(files,1));

newfiles=files(~logical(sum(d,2)))

Roland

Darin

unread,
Sep 3, 2010, 9:41:09 AM9/3/10
to
Thanks! Turns out i could compress those 14 lines into 1 line.....

files = setdiff(files,finishedfiles);

good times :)

TideMan <mul...@gmail.com> wrote in message <0da82bc4-f051-44cf...@x18g2000pro.googlegroups.com>...

0 new messages