[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing values
From: |
John W. Eaton |
Subject: |
Re: Passing values |
Date: |
Mon, 13 May 2002 15:52:12 -0500 |
On 12-May-2002, Mike Miller <address@hidden> wrote:
| In my simple example using argv, the script could be written like this:
|
| #!/usr/local/bin/octave -q
| format(argv(1,1:max(find(toascii(argv(1,:))!=32))))
| x = str2num(argv(2,:));
| disp(x^2)
With Octave 2.1.x, argv is a list of strings. Since the items in a
list don't all have to have the same length (or even the same type)
the elements of argv don't need to be padded with blanks, so you can
write
#! /usr/local/bin/octave -qf
format (nth (argv, 1));
x = str2num (nth (argv, 2));
disp (x^2);
The type of argv may change again from list to cell array, so then you
would be able to write
#! /usr/local/bin/octave -qf
format (argv{1});
x = str2num (argv{2});
disp (x^2);
If this does happen, the nth function will probably be extended to
work for both cells and lists, so your code would not have to change
again.
jwe
-------------------------------------------------------------
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
-------------------------------------------------------------