Path: news.mathworks.com!not-for-mail
From: "Johannes Huth" <johannes-huth@gmx.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: choosing particular elements of a matrix
Date: Tue, 10 Feb 2009 14:12:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 50
Message-ID: <gms1vi$1c$1@fred.mathworks.com>
References: <3ad3d647-8b4b-44f7-8a34-57874e98d155@z28g2000prd.googlegroups.com> <10bf59c3-7738-4dd1-ae69-767561be1569@k36g2000pri.googlegroups.com> <gmrvtt$ee6$1@fred.mathworks.com>
Reply-To: "Johannes Huth" <johannes-huth@gmx.de>
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 1234275122 44 172.30.248.37 (10 Feb 2009 14:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 10 Feb 2009 14:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1433076
Xref: news.mathworks.com comp.soft-sys.matlab:517311



> > F2=3Dabs(F1);
> > for i=3D1:256
> >      for j=3D1:256
> >           if  F2(i,j)>2600
> >             F2(i,j)=3D3000;
> >           end
> >       end



> >   end
> > 
> > Here F1 is a complex matrix got by finding fft of an image of size
> > 256x256.
> > 
> >  Thanks!
> 
> ok, so add the r calculation to your loop and then when r<something set the matrix value to your R value.

Maybe its better to use logical indexing instead of loops:
F2(F2>2600)=3D3000; % to replace the upper loops

if you use 'find' your next problem can be solved as easily:

[row,col] = find(F2>2600);
F2(row,col) = 3D3000; % replaces upper loop

% now the radius thing...
%Lets say the center point is 
c = [128 128];

% You already got the indicees of all elements of F2 which are grater than 2600 in [row,col]. So make use of it. 
% compute the difference between each element an the center point c
vdiff = [row,col]-(ones(numel(row),1)*c);

% compute the length of each vector element (each row [x y])
diff = sqrt(sum(vdiff.*vdiff,2));

% find all elements in diff that are smaler than r
idx = diff<r;

% use idx to set the elements in F2:
F2(row(idx),col(idx)) = whatever;


I didn't try this, but loops in Matlab are rather slow. So maybe you give 'find' a try.

Regards
Joh