Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
filtrering complex numbers

Subject: filtrering complex numbers

From: Snow White

Date: 19 Aug, 2010 15:41:25

Message: 1 of 5

Hello,

I have the following vector:

bb=[1 2 3;1+1i 3 4] i want to filter out values cc=bb(bb>0.9&bb<3)

i get the following result:
cc =

   1.0000
   1.0000 + 1.0000i
   2.0000

although i want to filter out the complex number as well

cc=bb(isreal(bb)&bb>0.9&bb<3)

cc =

   Empty matrix: 0-by-1

is there any way of doing that?

Subject: filtrering complex numbers

From: Sean

Date: 19 Aug, 2010 15:48:26

Message: 2 of 5

"Snow White" <gulesaman@gmail.com> wrote in message <i4jjb5$46o$1@fred.mathworks.com>...
> Hello,
>
> I have the following vector:
>
> bb=[1 2 3;1+1i 3 4] i want to filter out values cc=bb(bb>0.9&bb<3)
>
> i get the following result:
> cc =
>
> 1.0000
> 1.0000 + 1.0000i
> 2.0000
>
> although i want to filter out the complex number as well
>
> cc=bb(isreal(bb)&bb>0.9&bb<3)
>
> cc =
>
> Empty matrix: 0-by-1
>
> is there any way of doing that?

A few tools:
help real
help imag

Subject: filtrering complex numbers

From: Matt Fig

Date: 19 Aug, 2010 16:03:23

Message: 3 of 5

First, bb is NOT a vector, it is a matrix.
Second:

cc=bb(imag(bb)==0&bb>0.9&bb<3) % Usual FP warnings apply.

Subject: filtrering complex numbers

From: Steven_Lord

Date: 19 Aug, 2010 16:28:53

Message: 4 of 5



"Snow White" <gulesaman@gmail.com> wrote in message
news:i4jjb5$46o$1@fred.mathworks.com...
> Hello,
>
> I have the following vector:
>
> bb=[1 2 3;1+1i 3 4] i want to filter out values cc=bb(bb>0.9&bb<3)
>
> i get the following result:
> cc =
>
> 1.0000 1.0000 + 1.0000i
> 2.0000
>
> although i want to filter out the complex number as well
>
> cc=bb(isreal(bb)&bb>0.9&bb<3)

ISREAL doesn't operate in an elementwise fashion; it return a scalar true if
the matrix does not have an imaginary part and a scalar false if it does.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/isreal.html

Sean and Matt's suggestion to use REAL and IMAG is the way I would approach
this problem.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: filtrering complex numbers

From: Snow White

Date: 19 Aug, 2010 16:36:22

Message: 5 of 5

thank you all... the following worked

tt=logical(imag(cc));cc(tt)=0;

"Steven_Lord" <slord@mathworks.com> wrote in message <i4jm44$48r$1@fred.mathworks.com>...
>
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:i4jjb5$46o$1@fred.mathworks.com...
> > Hello,
> >
> > I have the following vector:
> >
> > bb=[1 2 3;1+1i 3 4] i want to filter out values cc=bb(bb>0.9&bb<3)
> >
> > i get the following result:
> > cc =
> >
> > 1.0000 1.0000 + 1.0000i
> > 2.0000
> >
> > although i want to filter out the complex number as well
> >
> > cc=bb(isreal(bb)&bb>0.9&bb<3)
>
> ISREAL doesn't operate in an elementwise fashion; it return a scalar true if
> the matrix does not have an imaginary part and a scalar false if it does.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/isreal.html
>
> Sean and Matt's suggestion to use REAL and IMAG is the way I would approach
> this problem.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Tags for this Thread

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.

Contact us