Borrar filtros
Borrar filtros

Organising data into new matrix nxp

3 visualizaciones (últimos 30 días)
scour_man
scour_man el 8 de Jul. de 2011
Hi! I have several matrices (Z1, Z2, Z3 etc.) all of which are 322x202 and are values of depths from seabed surveys (each depth value within a matrix is for a different position). All surveys cover an identical area but are from different times (months/years apart). There are corresponding matrices X and Y which hold the latitude and longitude positions allowing visualisation of data by contour plot etc.
What I would like to do (in order for some statistical analysis) is rearrange the data into one matrix nxp where n is the number of timesteps and p is the positions.
I understand how to do this for very small matrices by matrix indexing but this is extremely tedious and time consuming... how can I do it quickly for my large matrices?
Any help much appreciated
  1 comentario
Oleg Komarov
Oleg Komarov el 8 de Jul. de 2011
So, do you want timestamp|lat|lon|value ?

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 8 de Jul. de 2011
The fact that your original Zn matrices are named like that makes things a bit awkward. You might want to read this:
to learn ways to avoid that, if possible.
However, if you are stuck with those variable names, then you can do something like the following:
N = 2; % Number of individual Z arrays (i.e. time steps)
Z1 = rand(3,4);
Z2 = rand(3,4);
% Get all the individual Z arrays into one big one
Z = zeros(3,4,N);
for i = 1:N
eval(['Z(:,:,i)=Z',num2str(i)]);
end
% Permute so that the time dimension is the first dimension
Z_time_first = permute(Z,[3 1 2]);
% Reshape so that the array is (number time steps X number observations)
Z_time_by_observations = reshape(Z,[2,12]);
I am not 100% sure this is what you meant, but I hope it has all the components you need to do what you want.
  2 comentarios
scour_man
scour_man el 8 de Jul. de 2011
Perfect. Thank you!
Oleg Komarov
Oleg Komarov el 8 de Jul. de 2011
I really recommend to store your Z1,Z2...as Z(:,:,1:n) since the beginning, if you can intervene in that part of the cycle.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by