Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Greatest commmon divisor
Date: Tue, 16 Dec 2008 07:54:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <gi7mqt$87b$1@fred.mathworks.com>
References: <ghukju$ksu$1@fred.mathworks.com> <ghul2u$rfp$1@fred.mathworks.com> <ghum4l$d95$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 1229414045 8427 172.30.248.37 (16 Dec 2008 07:54:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 16 Dec 2008 07:54:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:507238


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ghum4l$d95$1@fred.mathworks.com>...
> "Feng" <nclxin@hotmail.com> wrote in message <ghul2u$rfp$1@fred.mathworks.com>...
> > "Feng" <nclxin@hotmail.com> wrote in message <ghukju$ksu$1@fred.mathworks.com>...
> > > Hi, any one know how can get the gcd for an array. The function gcd() in matlabe > will give result for two scalar numbers.
> > > for example I want to get 2 for the array A= [10 2 10 -4 2 0];
> > > Is there any function to do that? or how can I do that? 
> > > 
> > > Thanks
> 
>   You could always use an old-fashioned for-loop:
> 
> c = A(1);
> for k = 2:length(A)
>  c = gcd(c,A(k));
> end
> 
> Roger Stafford


What about

min(gcd(A(1:end-1),A(2:end)))

Jos