Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: compare two vectors
Date: Sun, 2 Nov 2008 05:48:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <gejeui$hpf$1@fred.mathworks.com>
References: <geit6f$8ev$1@fred.mathworks.com> <gej3qa$609$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225604882 18223 172.30.248.37 (2 Nov 2008 05:48:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 2 Nov 2008 05:48:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 300906
Xref: news.mathworks.com comp.soft-sys.matlab:498484

Maybe you are looking for something like this that returns the dissimilar elements?

a=[1 1 1 1 1 2 2 3 4 5 6 7]';
b = [1 1 2 2 5 6]';
r = zeros(1,length(a)-length(b));
r_c = 1;

for i = 1:max(a)
    k = (sum(a==i) - sum(b==i));
    if k > 0
        for j = 1:k
            r(r_c) = i;
            r_c = r_c + 1;
        end
    end
end

Seth

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <gej3qa$609$1@fred.mathworks.com>...
> "ann au" <fannylyy@hkusua.hku.hk> wrote in message <geit6f$8ev$1@fred.mathworks.com>...
> > Hi,
> > 
> > I have two vectors:
> > 
> > a=[1 1 1 1 1 2 2 3 4 5 6 7]'
> > b = [1 1 2 2 5 6]'
> > 
> > I want to get the following result:
> > r = [1 1 1 3 4 7]'
> > 
> > What code can I use?
> > Thanks a lot!
> > 
> > Ann
> -----------------------------------------------------
> Not exactly sure what you're after, or what algorithm you're using, but this will work   ;-)
> 
> a=[1 1 1 1 1 2 2 3 4 5 6 7]'
> b = [1 1 2 2 5 6]'
> r = CompareVectors(a, b);
> 
> function returnArray=CompareVectors(a, b)
>     returnArray = [1 1 1 3 4 7];
>     return;