Help with reshaping large 2D array --> 3D array -- order matters!!

Hi there - I need help reshaping a 2D array I have imported from a temperature data CSV file to a 3D array (lat x long x time).
Right now, every row is data from a single time period, with points from different gridpoints populating the rows.
I effectively want to take something like this:
x1y1t1 x1y2t1 x2y1t1 x2y2t1;
x1y1t2 x1y2t2 x2y1t2 x2y2t2;
And want it to be:
(:,:,1) =
x1y1t1 x1y2t1;
x2y1t1 x2y2t1
(:,:,2) =
x1y1t2 x1y2t2
x2y1t2 x2y2t2
In actuality, I'm trying to get my (84 x 259,200) [t x (lat*long)] array to be a (360 x 720 x 84) [lat x long x t] one.
When I use the reshape function ... ie: reshape(A,360,720,84) .. or in conjunction with the ipermute function, it still rearranges it incorrectly :( I can manage to keep data from the correct months (t) in the right dimension, but my lat x long just gets messed up! I've been fighting with this all week and have reached an impasse with Matlab! Any help would be greatly appreciated!!
Note: I actually am getting the 2D csv data from a process I do in numpy - if anyone has any suggestions on a better text file format to export (perhaps one that can maintain a 3D shape?) from python, I would love to hear that too! I cannot get the netcdf/hdf toolkits to work on my laptop unfortunately - so it would have to be a more simple text format I think.

댓글 수: 1

I have experimented with the Matlab (R20112a) support of NetCDF4 and HDF5. My impression is that they are okey, with the exception of low level HDF5, which is too much low level - IMO.

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 9월 14일
A = randi(1000,84,259200); % A - initial array
out = reshape(A',360,720,[]);

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2012년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by