Organising data into new matrix nxp
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Réponse acceptée
the cyclist
le 8 Juil 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 commentaires
Oleg Komarov
le 8 Juil 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!