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
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
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 Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!