help-octave
[Top][All Lists]

## Re: is octave compatible with matlab 5.2?

 From: A. Scottedward Hodel Subject: Re: is octave compatible with matlab 5.2? Date: Tue, 23 Mar 1999 14:20:35 -0600

```Thanks for writing the clarification; I was being brief (a.k.a. lazy).

>>handle 1-d list data structures.
>
>Not sure what you mean by that; they're real lists and they can
>contain lists.  So this works:
>
>foo=list([1,2], list([3,4]))
>
>But lists *are* bleeding edge; so far, I haven't found a way to get
>stuff out of lists. :-(  so foo(2) in the above doesn't return a
>list of one item.  Neither does foo(2)(1).
>

The "nth" function is what you're looking for (returns the nth element in a
list).
JWE and exchanged a bunch of email on how to handle this.

x=1:3; foo(x)         returns a list
x = 1; foo(x)
Should this be a list of a singleton?  For consistency, we decided
on a list of length 1; use the nth function to get the singleton.

octave:1> foo=list([1,2], list([3,4]))
foo =
(
[1] =

1  2

[2] =
(
[1] =

3  4

)
)
octave:2> foo(2)
ans =
(
[1] =
(
[1] =

3  4

)
)
octave:3> nth(foo,2)
ans =
(
[1] =

3  4

)
octave:4> nth(nth(foo,2),1)
ans =

3  4

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 ED-13, MSFC, Alabama, 35812
http://www.eng.auburn.edu/~scotte

```