[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variable length arrays to be inserted into a single list.
From: |
A. Scottedward Hodel |
Subject: |
Re: variable length arrays to be inserted into a single list. |
Date: |
Thu, 07 Oct 1999 16:08:26 -0500 |
The "bleeding-edge" release of Octave has a list data structure which I have
often used for this very purpose. Unlike the MATLAB cell structure, octave
lists are only 2-d. (another entry in a long to do list for octave
developers...)
example: file jnk.m:
mystruct.x = 1;
mystruct.y = 2;
x = list("string variable",[1 2 3],mystruct) # can mix variable types
y = x(1:2) # sub-list
z = x(1) # length 1 sublist
w = nth(x,1) # "nth" entry in the list
GNU Octave, version 2.1.14 (powerpc-apple-machten4).
Copyright (C) 1996, 1997, 1998 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.
octave:1> jnk
x =
(
[1] = string variable
[2] =
1 2 3
[3] =
{
x = 1
y = 2
}
)
y =
(
[1] = string variable
[2] =
1 2 3
)
z =
(
[1] = string variable
)
w = string variable
--
A S Hodel Assoc. Prof. Dept Elect Eng, Auburn Univ,AL 36849-5201
On leave at NASA Marshall Space Flight Center (256) 544-1426
Address until 15 Mar 2000:Mail Code TD-55, MSFC, Alabama, 35812
http://www.eng.auburn.edu/~scotte
----------
>From: Kharidehal Lakshmi A <address@hidden>
>To: address@hidden
>Subject: variable length arrays to be inserted into a single list.
>Date: Thu, Oct 7, 1999, 3:53 PM
>
> hi,
> i have 2 doubts in octave.if u know the answer please mail me back.
>
> 1) Suppose I have N variable length arrays:
>
> [ 1 4 5]
> [ 3 ]
> [ 4 76 89]
> []
> [ 3 56 ]
> .
> .
> .
> [ 87 4 32 3 ]
>
> I want to put these arrays in a bigger data structure, so that I can
> retrieve any of these arrays when I need them. For this I want to use an
> index. For example, if we were using language C++, it would be:
>
> ---
> int **list;
>
> list = new list[N]; // N pointers to arrays
>
> for (int i=0; i<N; i++) {
> list[i] = myCustomList(i);
> }
> ---
>
> where the function myCustomList() returns type int* (an integer array) of
> variable size. Of course in this program we will also need to store the
> length of the arrays somewhere. Otherwise I won't be able to know how
> many elements are stored in list[i] for any i. (MATLAB knows the length
> of arrays so I didn't need to store it.)
>
> Now, to have the same functionality in MATLAB, I can use the following
> syntax:
>
> ---
> list = { [2 3 5], [ 4 ], [54 545 6 66 ], [], .... , [3 ], [23 34 5] };
> ---
>
> where list(1) will be [ 2 3 5 ] and list(2) will be [ 4 ].
>
> I don't know how to do this in Octave. Octave doesn't have the {}
> operators (in MATLAB they are called 'cell structures').
>
> 2) the second question is
> the switch structure in matlab doesn't recognise the value
> of the case expression to be a string,it considers it to be a matrix
> of length equal to the length of the string and gives us an error.
> how do u use it.
>
> please mail to me at address@hidden as early as possible.
>
> thanks very much
>
> bye
> lakshmi
>
>
>
> ---------------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL. To ensure
> that development continues, see www.che.wisc.edu/octave/giftform.html
> Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
> ---------------------------------------------------------------------
>
---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------