[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: plot data from multiple arguments
From: |
Etienne Grossmann |
Subject: |
Re: plot data from multiple arguments |
Date: |
Mon, 29 Oct 2001 10:01:32 +0000 |
User-agent: |
WEMI/1.13.7 (Shimada) FLIM/1.13.2 (Kasanui) Emacs/20.7 (i386-debian-linux-gnu) (with unibyte mode) |
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?).
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
-------------------------------------------------------------