help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

plot complex data


From: Ted Harding
Subject: plot complex data
Date: Sun, 22 May 1994 14:50:38 +0100 (BST)

> Date: Sat, 21 May 1994 17:13:50 -0700 (PDT)
> From: John Utz <address@hidden>
> Subject: plot blues
> 
> Can anybody tell me what I am doing wrong here?:
> octave:5> plot (fft(real(cos(0:1:16))))
> 
> gnuplot> plot "/var/tmp/tmp.d19569" title "line 1"
>                                     ^
>          line 0: bad data on line 4
----------------------------------------------------------------------------
> Date: Sat, 21 May 1994 21:33:08 -0400
> From: address@hidden (L Jonas Olsson)
> 
> You can try:
> 
> plot([imag(fft(real(cos(0:1:16)))); real(fft(real(cos(0:1:16))))]')
> 
> Not very elegant, but works.
----------------------------------------------------------------------------
Actually, the real problem is a bug in plot_int.m
Try (A):
  X=(cos(0:16) + i*sin(0:16))'; plot(X)  --> "bad data in line 4"
But (B):
  X=(cos(1:16) + i*sin(1:16))'; plot(X)  --> Nice Plot! (x=Re, y=Im)
The reason is that in plot_int(x1,x2) the args are tested for real/complex
by "if imag(x1)" and the like. If ANY component of imag(x1)=0, test fails.
Hence (A) fails because sin(0)=0, but (B) works because no sin(1:16)=0.
PATCH: change the following in plot_int.m:
  if (x1_i)       --->       if any(x1_i)
  if (imag (x1))  --->       if any(imag (x1))
  if (imag (x2))  --->       if any(imag (x2))
and it works. Actually
  plot(fft(cos(0:1:16)))
now looks rather pretty!.

Though this fixes this particular problem, the whole matter of octave "plot"
and its interface with gnuplot needs sorting out. There are other problems.
One is to do with the fact that, though gnuplot can calculate complex
expressions, it doesn't seem able to handle them for plotting.
E.g (in gnuplot)
    j={0,1}      (gnuplot's version of 0+1i)
    plot [0:16] cos(x) + j*sin(x)               [try it]
doesn't work, while
    plot [0:16] real(cos(x)+j*sin(x)), imag(cos(x)+j*sin(x))
does.
Nor does gnuplot seem able to _read_ complex data: if "datafile" contains
{x1,y1}
{x2,y2}
...
you don't seem to be able to do anything sensible with it. Not that it
would matter, in octave, if you could, because when _octave_ sends
complex data to gnuplot the tmp/ datafile is in the format
(x1,y1)
(x2,y2)
...
which is NOT gnuplot complex number format (and is the immediate source
of the "bad data on line 4" messages). There are other problems too.
I'm looking into these, and will post any useful findings.
Ted Harding                                   address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]