Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Issue with index exceeding matrix sizes
Date: Mon, 18 Jul 2011 09:51:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <j00vmc$61i$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1310982668 6194 172.30.248.48 (18 Jul 2011 09:51:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 18 Jul 2011 09:51:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2953149
Xref: news.mathworks.com comp.soft-sys.matlab:736578

Just wondering if anyone can see the problem with this section of code, I have been through each line seperately and pinpointed that the issue is within the for loop

Many thanks for your time

 INPUT = ones(6,6) ;
[m n] = size(INPUT) ;
SEGMENT_MAP = zeros(m,n);
segment_number = 1 ;

[idx idy] = find(INPUT==1) ;

idy(idx==1) = [] ; idx(idx==1) = [] ;
idy(idx==m) = [] ; idx(idx==m) = [] ;
idx(idy==1) = [] ; idy(idy==1) = [] ;
idx(idy==n) = [] ; idy(idy==n) = [] ;

for count=1:length(idx)
    i = idx(count) ;
    j = idy(count) ;
    b = reshape(SEGMENT_MAP(i-1:i+1,j-1:j+1),1,[]) 
    if (sum(b) == 0)
        a = segment_number ;
        segment_number = segment_number+1 ;
    else 
        a = min(b(b>0)) ;
    end
    SEGMENT_MAP(i,j) = a;
end
SEGMENT_MAP