[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating a varargin-like object
From: |
Miquel Cabanas |
Subject: |
Re: Creating a varargin-like object |
Date: |
Mon, 20 Feb 2006 10:25:00 +0100 |
hi,
On Mon, 2006-02-20 at 00:50 -0500, Edward C. Jones wrote:
> I use the Debian package octive2.1 version 1:2.1.72-10.
Debian is great! it's actually so great that it comes with all the
answers to your questions. For that you should have installed the
packages,
octave2.1-htmldoc - HTML documentation on the GNU Octave lang
octave2.1-info - GNU Info documentation on the GNU Octave
You can access the HTML documentation from http://localhost/dwww ,
search for "octave" in the "Debian documentation Menu". Afterwards,
select the "The GNU Octave Manual". You could try and see if the link
below works for you,
http://localhost/cgi-bin/dwww?type=html&location=/usr/share/doc/octave2.1-htmldoc/octave_toc.html
If you want too a printed copy of the manual, install
octave2.1-doc - PDF documentation on the GNU Octave langu
> What kind of an object is c{:}? Note the curly brackets.
It's a container called "cell array". For more information, see Chapter
7 in the manual,
http://localhost/cgi-bin/dwww?type=file&location=/usr/share/doc/octave2.1-htmldoc/octave_8.html
> The octave source code is full of stuff like:
>
> function plot (varargin)
> __plt__ ("plot", varargin{:});
>
> Why are the curly brackets used?
>
varargin is a built-in cell array used to pass an arbitrary number of
arguments to a function. In this case, you will find a more in depth
explanation in the Octave wiki,
http://wiki.octave.org/wiki.pl?VariableLengthArgumentLists
> Suppose I have a collection of strings 'A', 'B', ... What should XXX be in
> the following:
> XXX = ?????
> menu('sometext', XXX)
> so that the choices in the menu are 'A', 'B', etc. In other words, how do I
> create a varargin-like object from scratch?
I'm not sure to understand your question, the menu() function is used to
display a menu on screen and to prompt for a valid answer. For instance
(a clearly unbiased question)
octave:1> reply = menu("Do you like Octave?", "yes", "absolutely", "it's
great");
Do you like Octave?
[ 1] yes
[ 2] absolutely
[ 3] it's great
pick a number, any number: 3
octave:2> reply
reply = 3
As for creating a cell array, you should use the functions cell()
---that you used in your message--- and cellstr(). Maybe this later is
what you're looking for. First you create a string array,
octave:3> strarray = [ "a" "b" "c" "d"]'
strarray =
a
b
c
d
Note the transpose, otherwise the array elements will be concatenated
into a single string. Then you use the cellstr() function to build a
cell array,
octave:4> cellstr (strarray)
ans =
{
[1,1] = a
[2,1] = b
[3,1] = c
[4,1] = d
}
Hope this helps,
Miquel
-------------------------------------------------------------
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
-------------------------------------------------------------