help-octave
[Top][All Lists]
Advanced

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

Re: plot data from multiple arguments


From: D. Stimits
Subject: Re: plot data from multiple arguments
Date: Mon, 29 Oct 2001 05:18:29 -0700

Etienne Grossmann wrote:
> 
>   Hi,
> 
>   The result of your TestMe() function should be ok, isn't it? What's
> wrong is the printed output.  The following function will print
> properly w/ a vector x and scalar y and z.
> 
> function retval = TestMe( x, y, z )
>   printf( "\nx, y, z: %f, %d, %d\n",[x'; [y;z]*ones(1,rows(x))]);
>   retval = x + y;
> endfunction
> 
> data = [x, TestMe(x,3,2)];
> plot (data(:,1),data(:,2));
> 
>   Your prob has to do w/ printf that matches the %X slots to the
> passed arguments, in the order in which it finds them (what else?).

That fixes the printf, but the underlying real problem that prompted me
to add the printf as debugging information is still there. The value of
"y" and "z" (2nd and 3rd arguments) still cannot be set to a particular
value like this:
data = [x, TestMe(x,3,2)];
# the above breaks if there is more than 1 argument, further parameters
can't be forced to any value.

The "3" and "2" might print without losing every other output, but "3"
and "2" will not be honored, and other values will be substituted. How
can I bind "3" and "2" as arguments 2 and 3? Else I have to manually
construct "data" one member at a time. It seems that there is a bug.

D. Stimits, address@hidden

> 
>   Hth,
> 
>   Etienne
> 
> From: "D. Stimits" <address@hidden>
> 
> #  I'm trying to plot a function that is similar to sin(). I can easily do
> #  this:
> #  x = (0.0:0.1:1.0)';
> #  data = [x, sin(x)];
> 
> #  ...and then plot via "data".
> 
> #  However, I have a function that takes 3 arguments, not 1. Two of the
> #  arguments will be held constant and only the first argument is being
> #  used with "x":
> #  function retval = TestMe( x, y, z )
> #     printf( "\nx, y, z: %f, %d, %d\n", x, y, z );
> #     retval = x + y;
> #  endfunction
> 
> #  (it'll always be called with x as a float between 0.0 and 1.0, y will
> #  always be 3, and z will always be 2)
> 
> #  Unfortunately, only the "x" argument is behaving properly. The "y" and
> #  "z" arguments should always be printed out as 3 and 2, but they are not.
> #  I don't seem to understand this, I thought that "[x, Function(x,3,2)]"
> #  would result in 10 rows of data (since x was assigned 10 values), and be
> #  two columns wide (since "x" takes one column, and "Function" returns
> #  another single value). The second and third arguments to Function should
> #  *ALWAYS* be 3 and 2, since those are explicitly stated, and variables
> #  are not used. But they are accurate only once. Then they change:
> #  octave:1> x = ( 0.0:0.1:1.0 )';
> #  octave:2> function retval = TestMe( x, y, z )
> #  >    printf( "\nx, y, z: %f, %d, %d\n", x, y, z );
> #  >    retval = x + y;
> #  > endfunction
> #  octave:3> data = [x, TestMe(x,3,2)];
> 
> #  x, y, z: 0.000000, 0, 0
> 
> #  x, y, z: 0.300000, 0, 0
> 
> #  x, y, z: 0.600000, 0, 0
> 
> #  x, y, z: 0.900000, 1, 3
> 
> #  x, y, z: 2.000000, octave:4>
> 
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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