Thread Subject: choosing particular elements of a matrix

Subject: choosing particular elements of a matrix

From: learner

Date: 10 Feb, 2009 11:19:10

Message: 1 of 5

Hi..!

I have a matrix of complex numbers, say a matrix of dimension 256x256.
I also have a radius,r = sqrt((real)^2+(img)^2))i.e the absolute
value.

I want to set all the values of matrix from its center to the radius r
equal to another higher value R. Please help.

Thank you

Subject: choosing particular elements of a matrix

From: David

Date: 10 Feb, 2009 11:58:01

Message: 2 of 5

learner <learner388@gmail.com> wrote in message <3ad3d647-8b4b-44f7-8a34-57874e98d155@z28g2000prd.googlegroups.com>...
> Hi..!
>
> I have a matrix of complex numbers, say a matrix of dimension 256x256.
> I also have a radius,r = sqrt((real)^2+(img)^2))i.e the absolute
> value.
>
> I want to set all the values of matrix from its center to the radius r
> equal to another higher value R. Please help.
>
> Thank you

ok, so what have you done so far?

Subject: choosing particular elements of a matrix

From: learner

Date: 10 Feb, 2009 13:12:47

Message: 3 of 5

On Feb 10, 4:58=A0pm, "David" <d...@bigcompany.com> wrote:
> learner <learner...@gmail.com> wrote in message <3ad3d647-8b4b-44f7-8a34-=
57874e98d...@z28g2000prd.googlegroups.com>...
> > Hi..!
>
> > I have a matrix of complex numbers, say a matrix of dimension 256x256.
> > I also have a =A0radius,r =3D sqrt((real)^2+(img)^2))i.e the absolute
> > value.
>
> > I want to set all the values of matrix from its center to the radius r
> > equal to another higher =A0 value R. Please help.
>
> > Thank you
>
> ok, so what have you done so far?

I only have the image matrix and r value... I am a beginner... am
still learning ,
but i have set all values above a threshold to a constant value for
the entire matrix..but what i require is to set values within radius r
to the value R.


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!

Subject: choosing particular elements of a matrix

From: David

Date: 10 Feb, 2009 13:37:01

Message: 4 of 5

learner <learner388@gmail.com> wrote in message <10bf59c3-7738-4dd1-ae69-767561be1569@k36g2000pri.googlegroups.com>...
> On Feb 10, 4:58=A0pm, "David" <d...@bigcompany.com> wrote:
> > learner <learner...@gmail.com> wrote in message <3ad3d647-8b4b-44f7-8a34-=
> 57874e98d...@z28g2000prd.googlegroups.com>...
> > > Hi..!
> >
> > > I have a matrix of complex numbers, say a matrix of dimension 256x256.
> > > I also have a =A0radius,r =3D sqrt((real)^2+(img)^2))i.e the absolute
> > > value.
> >
> > > I want to set all the values of matrix from its center to the radius r
> > > equal to another higher =A0 value R. Please help.
> >
> > > Thank you
> >
> > ok, so what have you done so far?
>
> I only have the image matrix and r value... I am a beginner... am
> still learning ,
> but i have set all values above a threshold to a constant value for
> the entire matrix..but what i require is to set values within radius r
> to the value R.
>
>
> 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.

Subject: choosing particular elements of a matrix

From: Johannes Huth

Date: 10 Feb, 2009 14:12:02

Message: 5 of 5


> > 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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com