<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937</link>
    <title>MATLAB Central Newsreader - Greatest commmon divisor</title>
    <description>Feed for thread: Greatest commmon divisor</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 12 Dec 2008 21:21:02 -0500</pubDate>
      <title>Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#616711</link>
      <author>Feng</author>
      <description>Hi, any one know how can get the gcd for an array. The function gcd() in matlabe will give result for a array.&lt;br&gt;
for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
Is there any function to do that? or how can I do that? &lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Fri, 12 Dec 2008 21:29:02 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#616715</link>
      <author>Feng</author>
      <description>&quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghukju$ksu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi, any one know how can get the gcd for an array. The function gcd() in matlabe &amp;gt; will give result for two scalar numbers.&lt;br&gt;
&amp;gt; for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
&amp;gt; Is there any function to do that? or how can I do that? &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks</description>
    </item>
    <item>
      <pubDate>Fri, 12 Dec 2008 21:47:02 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#616717</link>
      <author>Roger Stafford</author>
      <description>&quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghul2u$rfp$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghukju$ksu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi, any one know how can get the gcd for an array. The function gcd() in matlabe &amp;gt; will give result for two scalar numbers.&lt;br&gt;
&amp;gt; &amp;gt; for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
&amp;gt; &amp;gt; Is there any function to do that? or how can I do that? &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;You could always use an old-fashioned for-loop:&lt;br&gt;
&lt;br&gt;
c = A(1);&lt;br&gt;
for k = 2:length(A)&lt;br&gt;
&amp;nbsp;c = gcd(c,A(k));&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 01:38:23 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617269</link>
      <author>Loren Shure</author>
      <description>In article &amp;lt;ghukju$ksu$1@fred.mathworks.com&amp;gt;, nclxin@hotmail.com says...&lt;br&gt;
&amp;gt; Hi, any one know how can get the gcd for an array. The function gcd() in matlabe will give result for a array.&lt;br&gt;
&amp;gt; for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
&amp;gt; Is there any function to do that? or how can I do that? &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Check out the function arrayfun&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren&quot;&gt;http://blogs.mathworks.com/loren&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 05:51:02 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617284</link>
      <author>Bruno Luong</author>
      <description>Loren Shure &amp;lt;loren@mathworks.com&amp;gt; wrote in message &amp;lt;MPG.23b0d09e505fb8f4989907@news.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Check out the function arrayfun&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I can't see how arrayfun would be used here. I rather stick with Roger's for-loop solution.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 07:54:05 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617299</link>
      <author>Jos </author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;ghum4l$d95$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghul2u$rfp$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghukju$ksu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi, any one know how can get the gcd for an array. The function gcd() in matlabe &amp;gt; will give result for two scalar numbers.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Is there any function to do that? or how can I do that? &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   You could always use an old-fashioned for-loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; c = A(1);&lt;br&gt;
&amp;gt; for k = 2:length(A)&lt;br&gt;
&amp;gt;  c = gcd(c,A(k));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
What about&lt;br&gt;
&lt;br&gt;
min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 07:59:07 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617303</link>
      <author>Jos </author>
      <description>&quot;Jos &quot; &amp;lt;#10584@fileexchange.com&amp;gt; wrote in message &amp;lt;gi7mqt$87b$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;ghum4l$d95$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghul2u$rfp$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &quot;Feng&quot; &amp;lt;nclxin@hotmail.com&amp;gt; wrote in message &amp;lt;ghukju$ksu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Hi, any one know how can get the gcd for an array. The function gcd() in matlabe &amp;gt; will give result for two scalar numbers.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; for example I want to get 2 for the array A= [10 2 10 -4 2 0];&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Is there any function to do that? or how can I do that? &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Thanks&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;   You could always use an old-fashioned for-loop:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; c = A(1);&lt;br&gt;
&amp;gt; &amp;gt; for k = 2:length(A)&lt;br&gt;
&amp;gt; &amp;gt;  c = gcd(c,A(k));&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; What about&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jos&lt;br&gt;
&lt;br&gt;
On second thoughts, you have to remove the zeros first, otherwise something like&lt;br&gt;
A = [x 0 0 y] &lt;br&gt;
will always give 0, instead of gcd(x,y)&lt;br&gt;
&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 08:09:06 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617306</link>
      <author>Bruno Luong</author>
      <description>&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Jos, this does not work&lt;br&gt;
&lt;br&gt;
A=[15 30 20]&lt;br&gt;
&lt;br&gt;
gcd is 5, not 10&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 08:16:05 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617307</link>
      <author>Roger Stafford</author>
      <description>&quot;Jos &quot; &amp;lt;#10584@fileexchange.com&amp;gt; wrote in message &amp;lt;gi7mqt$87b$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; What about&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jos&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;I don't think that would work, Jos, even with zeros eliminated.  Let A = [15,21,35].  Then gcd(A(1:end-1),A(2:end)) would yield [3,7] but the minimum of these is not the gcd of the three combined quantities.  The greatest common factor of all three is simply 1, not this minimum.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 10:04:03 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617323</link>
      <author>Jos </author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gi7o45$297$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Jos &quot; &amp;lt;#10584@fileexchange.com&amp;gt; wrote in message &amp;lt;gi7mqt$87b$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; What about&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Jos&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   I don't think that would work, Jos, even with zeros eliminated.  Let A = [15,21,35].  Then gcd(A(1:end-1),A(2:end)) would yield [3,7] but the minimum of these is not the gcd of the three combined quantities.  The greatest common factor of all three is simply 1, not this minimum.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
Yep, you and Bruno are right, of course. I was just wondering why Loren suggested arrayfun, and so I was looking for a function that could do this. &lt;br&gt;
&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Tue, 16 Dec 2008 15:16:09 -0500</pubDate>
      <title>Re: Greatest commmon divisor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240937#617376</link>
      <author>Loren Shure</author>
      <description>In article &amp;lt;gi7uei$22l$1@fred.mathworks.com&amp;gt;, #10584@fileexchange.com &lt;br&gt;
says...&lt;br&gt;
&amp;gt; &quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gi7o45$297$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Jos &quot; &amp;lt;#10584@fileexchange.com&amp;gt; wrote in message &amp;lt;gi7mqt$87b$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; What about&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; min(gcd(A(1:end-1),A(2:end)))&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Jos&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;   I don't think that would work, Jos, even with zeros eliminated.  Let A = [15,21,35].  Then gcd(A(1:end-1),A(2:end)) would yield [3,7] but the minimum of these is not the gcd of the three combined quantities.  The greatest common factor of all three is simply 1, not this minimum.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yep, you and Bruno are right, of course. I was just wondering why Loren suggested arrayfun, and so I was looking for a function that could do this. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jos&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Perhaps I misread the problem.  I thought the OP wanted GCD of each &lt;br&gt;
&quot;pair&quot; of points in 2 arrays.  Probably read too fast...&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren&quot;&gt;http://blogs.mathworks.com/loren&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

