help-octave
[Top][All Lists]

## Re: 3D array

 From: Laurent Jacques Subject: Re: 3D array Date: Wed, 14 Nov 2001 12:56:24 +0100

```On Wednesday 14 November 2001 02:11, address@hidden wrote:
> I haven't used N dim arrays in Matlab. For those who have:
> Is that Matlab implementation well thought out?
> Or are there inconsistencies and ambiguities (as is
> fairly common in some of the worse thought out parts of
> Matlab syntax)?

Well. It seems that in Matlab, the dimensions greater than 2 are extra
dimensions in the sense that they don't participate to standard algebric
manipulation.

Here are some very basic examples:
===
>> a = eye(3,3);   %% eye(3,3,3) not defined!
>> a(:,:,1) = eye(3,3);
>> a
a(:,:,1) =
1     0     0
0     1     0
0     0     1
a(:,:,2) =
1     0     0
0     1     0
0     0     1

>> a^2
??? Error using ==> ^
Input arguments must be 2-D.

>> (a+1).^2
ans(:,:,1) =
4     1     1
1     4     1
1     1     4
ans(:,:,2) =
4     1     1
1     4     1
1     1     4
===

The ".[operator]" is of course understood like the element to element
application of [operator] but you have too few of tensor consideration (like
the scalar, vectorial or array reductions).

There is just a function called squeeze which squeeze the zero element
dimension. In the preceeding example:
===
>> b=sum(a,1) %% Sum over the first dim
b(:,:,1) =
1     1     1
b(:,:,2) =
1     1     1
>> whos b
Name      Size           Bytes  Class

b         1x3x2             48  double array

Grand total is 6 elements using 48 bytes

>> squeeze(b)
ans =
1     1
1     1
1     1
===

L. Jacques.

-------------------------------------------------------------
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
-------------------------------------------------------------

```