<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Puzzler: Find largest connected island</title>
	<atom:link href="http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:06:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1160</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Wed, 10 Sep 2008 00:22:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1160</guid>
		<description>Check out find_components, on the File Exchange.  It doesn&#039;t require the Image Toolbox, just MATLAB itself:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=21366

which has lots of comments that explains what the code does, and some plots of the graph showing the connected components (graph, as in graph theory).  This Puzzler is a fun example of the kind of things dmperm is good for.

(Except that the Code Metrics don&#039;t display properly ... sigh).</description>
		<content:encoded><![CDATA[<p>Check out find_components, on the File Exchange.  It doesn&#8217;t require the Image Toolbox, just MATLAB itself:</p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=21366" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=21366</a></p>
<p>which has lots of comments that explains what the code does, and some plots of the graph showing the connected components (graph, as in graph theory).  This Puzzler is a fun example of the kind of things dmperm is good for.</p>
<p>(Except that the Code Metrics don&#8217;t display properly &#8230; sigh).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1153</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Mon, 08 Sep 2008 00:58:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1153</guid>
		<description>Oh, I&#039;m a bit dyslexic.  The code has a variable &quot;west&quot; that should be called &quot;east.&quot;  East and West are the same to me, and I always get rows vs columns mixed up too ...

The code on the File Exchange will have the right name.</description>
		<content:encoded><![CDATA[<p>Oh, I&#8217;m a bit dyslexic.  The code has a variable &#8220;west&#8221; that should be called &#8220;east.&#8221;  East and West are the same to me, and I always get rows vs columns mixed up too &#8230;</p>
<p>The code on the File Exchange will have the right name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1154</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Mon, 08 Sep 2008 00:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1154</guid>
		<description>The fix is to replace the max(diff(r)) line with:

&lt;pre&gt;&lt;code&gt;
[ignore b] = sortrows ([diff(r&#039;) a(p(r(1:end-1)))&#039;])
b = b (end) ;
&lt;/pre&gt;&lt;/code&gt;

I&#039;ll post a file on the File Exchange that&#039;s commented so you can see what the algorithm is doing.  The non-commented code is:

&lt;pre&gt;&lt;code&gt;
function c = mySolver (a)
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
t = length (W) + length (S) + N ;
A = sparse ([k(W);k(S);(1:N)&#039;], [west(W);south(S);(1:N)&#039;], ones(t,1), N, N) ;
[p q r s] = dmperm (A+A&#039;) ;
[ignore b] = sortrows ([diff(r&#039;) a(p(r(1:end-1)))&#039;])
b = b (end) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;
&lt;/pre&gt;&lt;/code&gt;

Thanks for pointing out the glitch.</description>
		<content:encoded><![CDATA[<p>The fix is to replace the max(diff(r)) line with:</p>
<pre><code>
[ignore b] = sortrows ([diff(r') a(p(r(1:end-1)))'])
b = b (end) ;
</code></pre>
<p></p>
<p>I'll post a file on the File Exchange that's commented so you can see what the algorithm is doing.  The non-commented code is:</p>
<pre><code>
function c = mySolver (a)
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
t = length (W) + length (S) + N ;
A = sparse ([k(W);k(S);(1:N)'], [west(W);south(S);(1:N)'], ones(t,1), N, N) ;
[p q r s] = dmperm (A+A') ;
[ignore b] = sortrows ([diff(r') a(p(r(1:end-1)))'])
b = b (end) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;
</code></pre>
<p></p>
<p>Thanks for pointing out the glitch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1156</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Sun, 07 Sep 2008 17:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1156</guid>
		<description>Matt,
Good point, thanks for catching that.  I missed that in the problem statement.

It&#039;s easy to fix.  The size of each component is given by diff(r), where the kth component is nodes p(r(k):r(k+1)-1) where a &quot;node&quot; is an entry in the linear-index order of the image a.

max(diff(r)) just finds the biggest one.  It&#039;s a small tweak to pick amongst the ties.  I&#039;ll post an update.</description>
		<content:encoded><![CDATA[<p>Matt,<br />
Good point, thanks for catching that.  I missed that in the problem statement.</p>
<p>It&#8217;s easy to fix.  The size of each component is given by diff(r), where the kth component is nodes p(r(k):r(k+1)-1) where a &#8220;node&#8221; is an entry in the linear-index order of the image a.</p>
<p>max(diff(r)) just finds the biggest one.  It&#8217;s a small tweak to pick amongst the ties.  I&#8217;ll post an update.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Fig</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1155</link>
		<dc:creator>Matt Fig</dc:creator>
		<pubDate>Sun, 07 Sep 2008 16:29:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1155</guid>
		<description>Tim,

There is a problem in your second code.  In the case when a zero block is the same size as a non-zero block, your code sometimes returns the zero block.

a = zeros(4) + triu(ones(4)) + diag([-1 -1 0 0])
vs.
a = zeros(4) + triu(ones(4)) + diag([0 0 -1 -1])</description>
		<content:encoded><![CDATA[<p>Tim,</p>
<p>There is a problem in your second code.  In the case when a zero block is the same size as a non-zero block, your code sometimes returns the zero block.</p>
<p>a = zeros(4) + triu(ones(4)) + diag([-1 -1 0 0])<br />
vs.<br />
a = zeros(4) + triu(ones(4)) + diag([0 0 -1 -1])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1159</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Thu, 04 Sep 2008 01:44:18 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1159</guid>
		<description>I left out the comments in the code, above.  Most of the functions should be familiar to most MATLAB users.  dmperm is the odd one; you can read more about dmperm and how it works, and look at its source code, here:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11740&amp;objectType=FILE</description>
		<content:encoded><![CDATA[<p>I left out the comments in the code, above.  Most of the functions should be familiar to most MATLAB users.  dmperm is the odd one; you can read more about dmperm and how it works, and look at its source code, here:</p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11740&#038;objectType=FILE" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11740&#038;objectType=FILE</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1158</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Thu, 04 Sep 2008 01:19:34 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1158</guid>
		<description>I was a little confused by all the back-and-forth discussion of zero blocks.  Is a block of zeros to be found, if it&#039;s the biggest?  Or are zeros to be ignored?  The version above intentionally ignores zeros.  If you want to include blocks of zeros, then do this instead.  Take your pick:

&lt;pre&gt;&lt;code&gt;

function c = mySolver (a)
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
t = length (W) + length (S) + N ;
A = sparse ([k(W);k(S);(1:N)&#039;], [west(W);south(S);(1:N)&#039;], ones(t,1), N, N) ;
[p q r s] = dmperm (A+A&#039;) ;
[siz b] = max (diff (r)) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;

&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I was a little confused by all the back-and-forth discussion of zero blocks.  Is a block of zeros to be found, if it&#8217;s the biggest?  Or are zeros to be ignored?  The version above intentionally ignores zeros.  If you want to include blocks of zeros, then do this instead.  Take your pick:</p>
<pre><code>

function c = mySolver (a)
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
t = length (W) + length (S) + N ;
A = sparse ([k(W);k(S);(1:N)'], [west(W);south(S);(1:N)'], ones(t,1), N, N) ;
[p q r s] = dmperm (A+A') ;
[siz b] = max (diff (r)) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;

</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1157</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Thu, 04 Sep 2008 01:12:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1157</guid>
		<description>Try this one.  It doesn&#039;t require any toolboxes, just &quot;sparse&quot; and &quot;dmperm&quot;.

&lt;pre&gt;&lt;code&gt;
function c = mySolver (a)
%MYSOLVER find the largest nonzero connected component
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
A = sparse ([k(W);k(S);(1:N)&#039;], [west(W);south(S);(1:N)&#039;], [a(W);a(S);(1:N)&#039;], N, N) ;
[p q r s] = dmperm (A+A&#039;) ;
[siz b] = max (diff (r)) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;
&lt;/code&gt;&lt;/pre&gt;

Here are some timings.  With

&lt;pre&gt;&lt;code&gt;
a = round (rand (2000)*9) ;
&lt;/code&gt;&lt;/pre&gt;

The code above takes just under 9 seconds, which is about 20 times faster than at least one of the earlier posts.  &quot;dmperm&quot; is also what the Image Processing Toolbox uses.  This code uses dmperm directly.</description>
		<content:encoded><![CDATA[<p>Try this one.  It doesn&#8217;t require any toolboxes, just &#8220;sparse&#8221; and &#8220;dmperm&#8221;.</p>
<pre><code>
function c = mySolver (a)
%MYSOLVER find the largest nonzero connected component
[m n] = size (a) ;
N = m*n ;
k = reshape (1:N, m, n) ;
west  = [(k (:,2:n) .* (a (:,1:n-1) == a (:,2:n))) zeros(m,1)] ;
south = [(k (2:m,:) .* (a (1:m-1,:) == a (2:m,:))) ; zeros(1,n)] ;
W = find (west) ;
S = find (south) ;
A = sparse ([k(W);k(S);(1:N)'], [west(W);south(S);(1:N)'], [a(W);a(S);(1:N)'], N, N) ;
[p q r s] = dmperm (A+A') ;
[siz b] = max (diff (r)) ;
c = zeros (m,n) ;
c (p ([r(b) : r(b+1)-1])) = 1 ;
</code></pre>
<p>Here are some timings.  With</p>
<pre><code>
a = round (rand (2000)*9) ;
</code></pre>
<p>The code above takes just under 9 seconds, which is about 20 times faster than at least one of the earlier posts.  &#8220;dmperm&#8221; is also what the Image Processing Toolbox uses.  This code uses dmperm directly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt fig</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1180</link>
		<dc:creator>matt fig</dc:creator>
		<pubDate>Wed, 20 Aug 2008 03:04:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1180</guid>
		<description>Good catch Anne, sorry about that.

Hey Doug, I don&#039;t have access to the toolboxes where I work yet, could you just say a little about how our (the non-toolbox folks) solutions compare speed-wise and scale-wise to the code using the toolboxes?

Also, speaking of scaling, I ran the profiler and found the bottleneck in my code, it was mostly the find statement at the end.  I spent a few minutes fixing it, and now it is way faster.  Especially for a larger problems, for example:

&lt;pre&gt; &lt;code&gt;
a = round(rand(500)*9);
tic,ms = mySolver(a);toc
Elapsed time is 0.717184 seconds.
&lt;/code&gt; &lt;/pre&gt;

This compares with about 50 seconds for my first crack at it!  This simply proves that a few minutes spent profiling can pay off big time.
Here is the code:

&lt;pre&gt; &lt;code&gt;
function [c] = mySolver(a)
%MYSOLVER finds the largest island of four-connected elements.
[row,col] = size(a);
tmp = [nan(row,1),a]; % Pad with NaNs.
tmp = [nan(1,col+1);tmp];
c = zeros(size(tmp)); % Mark the groups.
d = zeros(1,ceil(numel(a)/2)); % Hold the value of each group.
ln = d; % Hold the number of elements in each group.
cntr = 1; % Label the individual groups.

for ii = 2:row+1;
    for jj = 1:col;
        if tmp(ii,jj)==tmp(ii,jj+1) % look right.
            if tmp(ii,jj)==tmp(ii-1,jj+1) % look right-up diag.
                if ~c(ii-1,jj+1) &amp;&amp; ~c(ii,jj)
                    c(ii,jj) = cntr;
                    c(ii-1,jj+1) = cntr;
                    c(ii,jj+1) = cntr;
                    d(cntr) = a(ii-1,jj-1);
                    ln(cntr) = ln(cntr) + 3;
                    cntr = cntr + 1;
                elseif ~c(ii-1,jj+1)
                    c(ii-1,jj+1) = c(ii,jj);
                    c(ii,jj+1) = c(ii,jj);
                    ln(c(ii,jj)) = ln(c(ii,jj)) + 2;
                elseif ~c(ii,jj)
                    c(ii,jj) = c(ii-1,jj+1);
                    c(ii,jj+1) = c(ii-1,jj+1);
                    ln(c(ii-1,jj+1)) = ln(c(ii-1,jj+1)) + 2;
                else
                    idx = c(ii-1,jj+1); % Save this for now.
                    vct = c==c(ii-1,jj+1);
                    lnv = find(vct);
                    c(vct)=c(ii,jj);
                    c(ii,jj+1) = c(ii,jj);
                    ln(c(ii,jj)) = ln(c(ii,jj)) +  length(lnv)+1;
                    ln(idx) = ln(idx) - length(lnv);
                end
            elseif ~c(ii,jj)
                c(ii,jj) = cntr;
                c(ii,jj+1) = cntr;
                d(cntr) = a(ii-1,jj-1);
                ln(cntr) = ln(cntr) + 2;
                cntr = cntr+1;
            else
                c(ii,jj+1) = c(ii,jj);
                ln(c(ii,jj)) = ln(c(ii,jj)) + 1;
            end
        elseif tmp(ii,jj+1)==tmp(ii-1,jj+1) % look right-up diag.
            if ~c(ii-1,jj+1)
                c(ii,jj+1) = cntr;
                c(ii-1,jj+1) = cntr;
                d(cntr) = a(ii-1,jj);
                ln(cntr) = ln(cntr) + 2;
                cntr = cntr + 1;
            else
                c(ii,jj+1) = c(ii-1,jj+1);
                ln(c(ii-1,jj+1)) = ln(c(ii-1,jj+1)) + 1;
            end
        end
    end
end

clear tmp % free up memory.
c = c(2:end,2:end); % Remove padding.
idx = ln==max(ln); % Find the largest num of elements.
[idx2,idx2] = max(d(idx)); % And corresponding values.
grp = find(idx,idx2); % Make selection.
c(c~=grp(end)) = 0;  % Final matrix.
c(c==grp(end)) = 1;
&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Good catch Anne, sorry about that.</p>
<p>Hey Doug, I don&#8217;t have access to the toolboxes where I work yet, could you just say a little about how our (the non-toolbox folks) solutions compare speed-wise and scale-wise to the code using the toolboxes?</p>
<p>Also, speaking of scaling, I ran the profiler and found the bottleneck in my code, it was mostly the find statement at the end.  I spent a few minutes fixing it, and now it is way faster.  Especially for a larger problems, for example:</p>
<pre> <code>
a = round(rand(500)*9);
tic,ms = mySolver(a);toc
Elapsed time is 0.717184 seconds.
</code> </pre>
<p>This compares with about 50 seconds for my first crack at it!  This simply proves that a few minutes spent profiling can pay off big time.<br />
Here is the code:</p>
<pre> <code>
function [c] = mySolver(a)
%MYSOLVER finds the largest island of four-connected elements.
[row,col] = size(a);
tmp = [nan(row,1),a]; % Pad with NaNs.
tmp = [nan(1,col+1);tmp];
c = zeros(size(tmp)); % Mark the groups.
d = zeros(1,ceil(numel(a)/2)); % Hold the value of each group.
ln = d; % Hold the number of elements in each group.
cntr = 1; % Label the individual groups.

for ii = 2:row+1;
    for jj = 1:col;
        if tmp(ii,jj)==tmp(ii,jj+1) % look right.
            if tmp(ii,jj)==tmp(ii-1,jj+1) % look right-up diag.
                if ~c(ii-1,jj+1) &amp;&amp; ~c(ii,jj)
                    c(ii,jj) = cntr;
                    c(ii-1,jj+1) = cntr;
                    c(ii,jj+1) = cntr;
                    d(cntr) = a(ii-1,jj-1);
                    ln(cntr) = ln(cntr) + 3;
                    cntr = cntr + 1;
                elseif ~c(ii-1,jj+1)
                    c(ii-1,jj+1) = c(ii,jj);
                    c(ii,jj+1) = c(ii,jj);
                    ln(c(ii,jj)) = ln(c(ii,jj)) + 2;
                elseif ~c(ii,jj)
                    c(ii,jj) = c(ii-1,jj+1);
                    c(ii,jj+1) = c(ii-1,jj+1);
                    ln(c(ii-1,jj+1)) = ln(c(ii-1,jj+1)) + 2;
                else
                    idx = c(ii-1,jj+1); % Save this for now.
                    vct = c==c(ii-1,jj+1);
                    lnv = find(vct);
                    c(vct)=c(ii,jj);
                    c(ii,jj+1) = c(ii,jj);
                    ln(c(ii,jj)) = ln(c(ii,jj)) +  length(lnv)+1;
                    ln(idx) = ln(idx) - length(lnv);
                end
            elseif ~c(ii,jj)
                c(ii,jj) = cntr;
                c(ii,jj+1) = cntr;
                d(cntr) = a(ii-1,jj-1);
                ln(cntr) = ln(cntr) + 2;
                cntr = cntr+1;
            else
                c(ii,jj+1) = c(ii,jj);
                ln(c(ii,jj)) = ln(c(ii,jj)) + 1;
            end
        elseif tmp(ii,jj+1)==tmp(ii-1,jj+1) % look right-up diag.
            if ~c(ii-1,jj+1)
                c(ii,jj+1) = cntr;
                c(ii-1,jj+1) = cntr;
                d(cntr) = a(ii-1,jj);
                ln(cntr) = ln(cntr) + 2;
                cntr = cntr + 1;
            else
                c(ii,jj+1) = c(ii-1,jj+1);
                ln(c(ii-1,jj+1)) = ln(c(ii-1,jj+1)) + 1;
            end
        end
    end
end

clear tmp % free up memory.
c = c(2:end,2:end); % Remove padding.
idx = ln==max(ln); % Find the largest num of elements.
[idx2,idx2] = max(d(idx)); % And corresponding values.
grp = find(idx,idx2); % Make selection.
c(c~=grp(end)) = 0;  % Final matrix.
c(c==grp(end)) = 1;
</code> </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1179</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 19 Aug 2008 20:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/18/puzzler-find-largest-connected-island/#comment-1179</guid>
		<description>Anne,

At this point I will leave it up as is, since I made a mistake in the problem statement.  Instead of &quot;positive whole numbers&quot; I should have said &quot;nonnegative integers&quot; (0, 1, 2, 3,...)

Thanks for keeping me honest on terminology, once I get your address, a bunch of MATLAB swag will be on its way!

Thanks,
Doug</description>
		<content:encoded><![CDATA[<p>Anne,</p>
<p>At this point I will leave it up as is, since I made a mistake in the problem statement.  Instead of &#8220;positive whole numbers&#8221; I should have said &#8220;nonnegative integers&#8221; (0, 1, 2, 3,&#8230;)</p>
<p>Thanks for keeping me honest on terminology, once I get your address, a bunch of MATLAB swag will be on its way!</p>
<p>Thanks,<br />
Doug</p>
]]></content:encoded>
	</item>
</channel>
</rss>

