[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: 3D array

From: Ted Harding
Subject: RE: 3D array
Date: Tue, 13 Nov 2001 10:00:11 -0000 (GMT)

On 13-Nov-01 Laurent Jacques wrote:
> Hello,
> Do you plan to program 3D (and even ND) arrays into Octave ?
> If yes, do you think it is hard to realize ?
> For me, this is the main thing which prevents me to work only with
> octave for 
> my scientific tasks.
> Laurent.

As far as I know, John Eaton (nor other people who contribute
octave code) does not plan to extend octave to 3D arrays or

I can suggest two ways round this.

One is to simulate higher-dimensional arrays by computing an
index into a 1-dimensional array (see below).

The other, if you need a GPL program which does higher dimensions
natively, is to look at Tela ("Tensor Lab"):

This is very closely related to octave and to matlab. I think it
is probably closely compatible with octave as far as basic matrix
and vector manipulations are concerned, though I'm not sure how
much they have in common when it comes to matrix and vector functions
which are built out of the basic functions.

I hope this helps. See below for the octave multidimensional work-round.

Multidimensional arrays by computing an index into a 1-dim array.
It's convenient to use a "structure" as the object which encapsulates
the "n-dimensional array":
Although it is not possible to do it directly, in the form A(i,j,k), it
can be simulated by computing an index into a linear array stored in a

octave:11> A.ndim = 3;          # 3 dimensions
octave:12> A.dims = [3 2 4];    # dimensions of lengths 3, 2, 4
octave:13> A.elems = ...
>  [111 112 113 114   121 122 123 124 \
>   211 212 213 214   221 222 223 224 \
>   311 312 312 314   321 322 323 324 ];   # assign elements linearly
octave:14> function y = elem(A,i,j,k)      
> y = A.elems(k + A.dims(3)*(j-1) + A.dims(3)*A.dims(2)*(i-1));
> endfunction                              # function to access them
octave:15> elem(A,1,2,3)
ans = 123
octave:16> elem(A,2,2,4)
ans = 224

(where the last index varies most rapidly along the linear array and the
first least rapidly).

The function definition gets a bit more complicated if you have to allow
for arbitrary numbers of dimensions (use varargs)

E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 13-Nov-01                                       Time: 10:00:11
------------------------------ XFMail ------------------------------

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]