Organising data into new matrix nxp

3 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2011-7-8
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 个评论
Oleg Komarov
Oleg Komarov 2011-7-8
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by