Converting 1-D indexed array to 2-D/3-D matrix

조회 수: 5 (최근 30일)
John Cruce
John Cruce 2021년 9월 7일
편집: John Cruce 2021년 10월 2일
I have a 1-D array of radar data for latitude, longitude, and altitude (dimensions of 2301 x 1201 x 24). Since not all latitude, longitude, and altitudes contain measurable reflectivities (radar data), the radar data are stored as an indexed 1-D array to save storage space. (If all latitude, longitudes, and altitudes contained data, this 1-D array would span 66,324,024 (2301x1201x24) cells)
Indices are zero-based, with data stored in order of increasing Longitude, then Latitude, then Altitude. So for example, the southwest corner of the grid at the lowest altitude is index 0. The southeast corner of the grid at the lowest altitude is index 2300.
I need to get this 1-D array over to a 2-D array based on the first altitude level (or alternatively on a 3D array for lattitude, longitude, and altitude). What's the most efficient way to do this? Should I first create a 2-D index array then connect the index from the radar data with the 2-D array?
I posted this in early September and still haven't found a solution. Any suggestions would be greatly appreciated!

답변 (1개)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2021년 9월 7일
Your incresing order are usual for 3-D array. (X,Y,Z). just reshape the array, it would work:
data = reshape(data,[2301 1201 24]);
for knowing the indexes. you need to use a function to transform linear index to n-dim index.
the ind2sun transform linear index to n-dim index.
[lat,long,alt] = ind2sub([2301 1201 24],linear_index);
then lat, long, alt would be index of lattitude, longitude and altiture for linear_index. you should substrct 1 from them to make them zero-base indexes. also you can pass multiple index to this function:
[lat,long,alt] = ind2sub([2301 1201 24],1:66324024);
  댓글 수: 1
John Cruce
John Cruce 2021년 9월 13일
Thanks for the reply. The 1-D array of radar reflectivity data spans only 3,088,124 cells, since not all latitude/longitude/altitude combinations contain reflectivity data. In this case, 3,088,124 of 66,324,024 grid boxes (2301 x 1201 x 24) have measurable echoes.
The 1-D array index begins with 885, 886, 887...930,1730,1731...65277701. I have another corresponding 1-D array of radar reflectivity data. As previously mentioned, the southwest corner of the grid at the lowest altitude is index 0. The southeast corner of the grid at the lowest altitude is index 2300. So in outline I need to read the index and reflectivity arrays, create a 3-D array with dimensions (2301 x 1201 x 24), and then bring the reflectivity into that array using the index.
Does that make sense? I believe that's a little different from the solution proposed here.

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

카테고리

Help CenterFile Exchange에서 Environment and Clutter에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by