help-octave
[Top][All Lists]
Advanced

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

## Re: 2D matrixes into a 3D matrix

 From: Andres Sepulveda Subject: Re: 2D matrixes into a 3D matrix Date: Mon, 29 Jan 2007 19:49:48 -0300 (CLST) User-agent: SquirrelMail/1.4.4

```  Hi, sorry for the brief description.

I have 2D fields of sea surface tempereature, say 50x40, and I want to
put them in a 3D array, where the third index is time. The idea is to be
able to add more and more 2D fields for which I need a way to increase
the size of it from

(50x40x2) to (50x40x3) or (50x40x15), depending on data availability

is there a clever way to do this?

Andres

On Mon, January 29, 2007 5:39 pm, David Bateman said:
> Andres Sepulveda wrote:
>>  Hi,
>>
>>  I want to "stick" a series of 2D (e.g. 2x2) matrixes into a  3D matrix
>> (2x2xN) with N increasing as I stick a new matrix.
>>
>> Is it better to define a large-enough 3D matrix and then reduce its
>> size?
>>
>>        Andres
>>>
>
> I have no idea what you mean from the above statement. If you know the
> final size of the 3D matrix, then yes it is better to preallocate the
> memory something like
>
>
> A = zeros([2,2,N]);
> for i=1:N
>   A(:,:,i)= randn(2,2);
> endfor
>
>
> is definitely an advantage, though the above example is artificial and
> should be written as A = randn([2,2,2]) instead. Note that is you can
> vector the code as do without the loop to create the matrix, you are
> much better off without it...
>
> D.
>

```

reply via email to

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