Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren.shure@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: removing zero elements
Date: Fri, 16 Oct 2009 08:10:21 -0400
Organization: The MathWorks
Lines: 44
Message-ID: <MPG.25422cbc7d81ac43989a3a@news.mathworks.com>
References: <hb9l2n$a6s$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1255695021 16105 172.31.57.214 (16 Oct 2009 12:10:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Oct 2009 12:10:21 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:577808


In article <hb9l2n$a6s$1@fred.mathworks.com>, maha_k@mathworks.com 
says...
> I have pair of arrays 
> 
> x=[1,2,3,0,5,6,0];
> y=[3,0,5,6,7,0,9];
> 
> (these are simplified examples)
> 
> I would like to remove corresponding elements from both arrays if either of them have a zero in it.
> 
> so in the above example, I am looking to have an answer of
> 
> x=[1,3,5];
> y=[3,4,7];
> 
> How would I go about doing this?
> 
> any  help would be most useful.
> 
>  
> 

anyzero = any([x;y] ==0)
x(anyzero) = []
y(anyzero) = []

I think you have a typo in expected results.

>> x=[1,2,3,0,5,6,0];
>> y=[3,0,5,6,7,0,9];
>> anyzero = any([x;y] ==0)
anyzero =
     0     1     0     1     0     1     1
>> x(anyzero) = []
x =
     1     3     5
>> y(anyzero) = []
y =
     3     5     7

-- 
Loren
http://blogs.mathworks.com/loren