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: Hendrik Naumann
Subject: Re: plot data from multiple arguments
Date: Mon, 29 Oct 2001 14:31:17 +0100

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Montag, 29. Oktober 2001 10:38 schrieb D. Stimits:
> 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

I did

function retval = TestMe( x, y, z )
  retval = x + y + z;
endfunction
x = (0.0:0.1:1.0)';
octave:12> [x, TestMe(x,3,3)]
ans =
 
  0.00000  3.00000
  0.10000  3.10000
  0.20000  3.20000
  0.30000  3.30000
  0.40000  3.40000
  0.50000  3.50000
  0.60000  3.60000
  0.70000  3.70000
  0.80000  3.80000
  0.90000  3.90000
  1.00000  4.00000
 
octave:13> [x, TestMe(x,7,4)]
ans =
 
  0.00000  7.00000
  0.10000  7.10000
  0.20000  7.20000
  0.30000  7.30000
  0.40000  7.40000
  0.50000  7.50000
  0.60000  7.60000
  0.70000  7.70000
  0.80000  7.80000
  0.90000  7.90000
  1.00000  8.00000

And thats like it should be.

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

You should define 

function retval = TestMe( x, y, z )
val = ones(length(x),1);        
  retval = [x + y, val .* y, val .* z];
endfunction

Gives

octave:23> [x, TestMe(x,7,4)]
ans =
 
  0.00000  7.00000  7.00000  4.00000
  0.10000  7.10000  7.00000  4.00000
  0.20000  7.20000  7.00000  4.00000
  0.30000  7.30000  7.00000  4.00000
  0.40000  7.40000  7.00000  4.00000
  0.50000  7.50000  7.00000  4.00000
  0.60000  7.60000  7.00000  4.00000
  0.70000  7.70000  7.00000  4.00000
  0.80000  7.80000  7.00000  4.00000
  0.90000  7.90000  7.00000  4.00000
  1.00000  8.00000  7.00000  4.00000

Is that what you wanted?

Hendrik Naumann
- -- 
PGP ID 21F0AC0265C92061
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE73VolIfCsAmXJIGERAg0mAJwJN9DY9Uvf1i9oLfDW61o38WvcWgCdFANy
S2pzJNp+T7xmWOaXGnqjFEI=
=Ey9v
-----END PGP SIGNATURE-----



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