[Top][All Lists]

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

Re: 2D matrixes into a 3D matrix

From: antonio palestrini
Subject: Re: 2D matrixes into a 3D matrix
Date: Tue, 30 Jan 2007 04:01:56 +0100

If the time interval of the observations is regular
then you know how many observations you have in, let's say, a week or
a month, etc. and you can use the David solution.
In the case of irregular time observation interval, if you may guess
the maximum number of
observations, say Nmax, then set the size of the 3D matrix to this
number (with an impossible temperature!) and then cut the non-filled
part with the "excise" function applied to the vectorized matrix A. As
usual the code is more simple than the description

A = -1000*ones(50,40,Nmax);  # -1000 is impossible both in centigrade
and in fahrenheit
  ...write a loop from 1 to Nmax and fill the A matrix with the obs. you have
b = excise(A(:),-1000);   # cut the non-filled part and put the result
in the vector b
B = reshape(b,50,40,N);  # create the desired matrix with the
effective number of obs.

 In the case of no idea regarding the number of obs. then you have to
resize the 3D matrix every time, for example if A collects the first N
matrices then type

A(:,:,N+1) = B;

where B is the new matrix (50x40) recording the obs. N+1.


2007/1/29, Andres Sepulveda <address@hidden>:

  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?


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.

Help-octave mailing list

Prof. Antonio Palestrini
DSGSS - University of Teramo, Italy
e-mail: address@hidden

reply via email to

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