Path: news.mathworks.com!not-for-mail
From: "Ulrik Nash" <uwn@sam.sdu.dk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Updating matrix
Date: Fri, 10 Sep 2010 08:12:29 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 48
Message-ID: <i6cp9d$8pk$1@fred.mathworks.com>
References: <i6cmnv$k6r$1@fred.mathworks.com> <Whlio.23462$u16.16594@newsfe17.iad>
Reply-To: "Ulrik Nash" <uwn@sam.sdu.dk>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1284106349 9012 172.30.248.35 (10 Sep 2010 08:12:29 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Sep 2010 08:12:29 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2106050
Xref: news.mathworks.com comp.soft-sys.matlab:669044

Walter Roberson <roberson@hushmail.com> wrote in message <Whlio.23462$u16.16594@newsfe17.iad>...
> On 10/09/10 2:29 AM, Ulrik Nash wrote:
> 
> > Suppose I have:
> >
> > A = [1 2 0 4 0 0]
> >
> > and
> >
> > B = [1 2 3 6]
> >
> > Now I need to update A with information in B to create:
> >
> > A = [1 2 3 0 0 6]
> >
> > You will notice the following:
> >
> > * The numbers in B indicate the index-values in A
> > * If an none-zero value is present in both A and B, then that value
> > essentially remains.
> > * If there is a none-zero value in A that is not present in B, then that
> > value is set to zero.
> >
> > Do you guys have a neat and efficient procedure, which performs task?
> 
> setintersect() can tell you which values are in both matrices.
> 
> ismember() can tell you which values of one matrix are present in another.
> 
> Consider for example
> 
> A(~ismember(A,B)) = 0;



Hi Walter, thanks again for your help. I think this is very useful.

As I see it, however, this procedure changes A in the process.

I was thinking the following to find what is in B but not in A:

B(ismember(A,B)) = 0;

which gives B = 0 0 3 6

but now I still need to find what is in A and not in (the original) B. But the original B is gone...

How do I overcome this dilemma?