help-octave
[Top][All Lists]
Advanced

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

plot data from multiple arguments


From: D. Stimits
Subject: plot data from multiple arguments
Date: Mon, 29 Oct 2001 02:38:17 -0700

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> 

What also looks strange is that the final printf() statement is never
completely printed. The final printf never prints out anything for
arguments 2 or 3, and fails to print the newline. The 2nd and 3rd
arguments are never "3" and "2", I would expect them to always be 3 and
2. And since there are 10 "x" values, not 5, it appears that every other
one is completely missing, other than the newline being printed. I
verified that "x" consists of 10 values in increments of 0.1. Are these
bugs? Is there another way to fill up "data" without manually looping
and expicitly appending an answer to a matrix each loop?

Platform is Linux, Redhat 7.1. octave version is 2.1.33.

D. Stimits, address@hidden



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