Path: news.mathworks.com!not-for-mail
From: "Yumnam Kirani" <kirani.singh@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vector and array
Date: Tue, 15 Feb 2011 05:55:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <ijd4fp$d0q$1@fred.mathworks.com>
References: <c8b70a4e-96e2-4aca-8f5f-396c40ddb714@z20g2000yqe.googlegroups.com>
Reply-To: "Yumnam Kirani" <kirani.singh@gmail.com>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1297749305 13338 172.30.248.47 (15 Feb 2011 05:55:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 15 Feb 2011 05:55:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1030755
Xref: news.mathworks.com comp.soft-sys.matlab:710066

Ramzi <ramzib2@gmail.com> wrote in message <c8b70a4e-96e2-4aca-8f5f-396c40ddb714@z20g2000yqe.googlegroups.com>...
> Hello everybody
> How can I do the following without loop?
> 
> N=5;
> M=4;
> 
> x=rand(N,M)>0.5;
> y=rand(1,M)>0.5;
> % I hate this loop
> for i=1:N
>    z(i,:)=y & x(i,:);
> end
> 
> i.e I want to AND vector y with each row in x
You can make y have the same size as x by making each row has y. Then simply do anding on x and y. 

Yumnam Kirani Singh
Tronglaobi Awang Leikai