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:
imag and real don't work

Subject: imag and real don't work

From: Sandra

Date: 24 Jul, 2008 11:04:04

Message: 1 of 5

I am sure this must be a simple thing, but it is doing my
head in!!! imag and real don't work for me see below:

>> real(0.0116 + 0.3333i)
??? Subscript indices must either be real positive integers
or logicals.

>> real(2+3*i)
??? Subscript indices must either be real positive integers
or logicals.

>> imag(2+3*i)
??? Subscript indices must either be real positive integers
or logicals.


the last two are from the matlab example! what am I doing wrong?

any advice appreciated,
sandra

Subject: imag and real don't work

From: Dave Brackett

Date: 24 Jul, 2008 11:08:03

Message: 2 of 5

"Sandra " <smh31.nospam@sussex.ac.uk> wrote in message
<g69nj3$9he$1@fred.mathworks.com>...
> I am sure this must be a simple thing, but it is doing my
> head in!!! imag and real don't work for me see below:
>
> >> real(0.0116 + 0.3333i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
> >> real(2+3*i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
> >> imag(2+3*i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
>
> the last two are from the matlab example! what am I doing
wrong?


Check that you haven't assigned anything to i. i and j
should be reserved for complex numbers. type 'clear i' in
command window and then try again.
dave

Subject: imag and real don't work

From: John D'Errico

Date: 24 Jul, 2008 11:13:08

Message: 3 of 5

"Sandra " <smh31.nospam@sussex.ac.uk> wrote in message
<g69nj3$9he$1@fred.mathworks.com>...
> I am sure this must be a simple thing, but it is doing my
> head in!!! imag and real don't work for me see below:
>
> >> real(0.0116 + 0.3333i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
> >> real(2+3*i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
> >> imag(2+3*i)
> ??? Subscript indices must either be real positive integers
> or logicals.
>
>
> the last two are from the matlab example! what am I doing wrong?
>
> any advice appreciated,
> sandra

Every single new user does this. They create
a variable with the name of a function they
will later use.

Have you created variables named imag and
real? What should Matlab do when it sees
variables with that name, but you try to use
the functions of the same names?

Just for kicks, now create variables named
quit and exit, as well as clear. Make your life
interesting. ;-)

John

Subject: imag and real don't work

From: Bruno Luong

Date: 24 Jul, 2008 11:15:09

Message: 4 of 5

Rather check real and imag.

clear real imag % clear variables
which real
which imag

If it does not return built-in functions then you have a
files that overwrite MATLAB factory functions.

Bruno

Subject: imag and real don't work

From: Matt Fig

Date: 24 Jul, 2008 12:37:03

Message: 5 of 5

real = 1:4;
real(3+2*i)
??? Subscript indices must either be real positive integers
or logicals.

clear real
real(3+2*i)

ans =

     3

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