Path: news.mathworks.com!not-for-mail
From: "patricia " <tishi@live.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nested loop help
Date: Tue, 19 Jul 2011 10:27:28 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 50
Message-ID: <j03m6g$l9$1@newscl01ah.mathworks.com>
References: <j0205b$f2k$1@newscl01ah.mathworks.com> <j0244j$rg1$1@newscl01ah.mathworks.com>
Reply-To: "patricia " <tishi@live.co.uk>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1311071248 681 172.30.248.35 (19 Jul 2011 10:27:28 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 Jul 2011 10:27:28 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2550512
Xref: news.mathworks.com comp.soft-sys.matlab:736712

"Roger Stafford" wrote in message <j0244j$rg1$1@newscl01ah.mathworks.com>...
> "patricia " <tishi@live.co.uk> wrote in message <j0205b$f2k$1@newscl01ah.mathworks.com>...
> > .........
> > for c=size(A,2) % Number of columns
> >     for r=size(A,1); %Number of rows
> >         R = A(r:r+2, c:c+2);
> >         %Extract the features
> >         FM(regionNum, 1) = mean(mean(I));
> >         FM(regionNum, 2) = std2(I);
> >         regionNum = regionNum +1;
> >     end
> > end
> > .........
> - - - - - - - - - -
>   I see at least three problems here:
> 
> 1. When c is equal to size(A,2) then A(~,c+1) and A(~,c+2) are outside its range.  The same is true when r is equal to size(A,1).
> 
> 2. The indices c and r are clearly intended to range starting from 1, but this code just uses the end value for each one.
> 
>   The problems in 1. and 2. would be corrected by writing:
> 
>  for c = 1:size(A,2)-2
>   for r = 1:size(A,1)-2
> 
> 3. After obtaining the 3 x 3 region in R, the subsequent code does not use R but references a matrix called 'I', so no use is made of R in the for-loops.
> 
> Roger Stafford

Hi Roger

Thanks for your help, i am newto matlab and just trying to get my head round it all.  I have changed the start of the for loop to what you suggested. so my code is now the following, so im i right in thinking this is now calculating the features for the region?

clear;
A=getImageFunction;
regionNum=1;

for c = 1:size(A,2);  % Number of columns
  for r = 1:size(A,1);  %Number of rows
       R = A(r:r-2, c:c-2);
        %Extract the features
        FM(regionNum, 1) = mean(mean(A));
        FM(regionNum, 2) = std2(A);
        regionNum = regionNum +1;
        
    end
    
end

Regions_Calculated=regionNum;