필터 지우기
필터 지우기

Organising data into new matrix nxp

조회 수: 3 (최근 30일)
scour_man
scour_man 2011년 7월 8일
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
Oleg Komarov
Oleg Komarov 2011년 7월 8일
So, do you want timestamp|lat|lon|value ?

댓글을 달려면 로그인하십시오.

채택된 답변

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
scour_man
scour_man 2011년 7월 8일
Perfect. Thank you!
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