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

1 次查看(过去 30 天)
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
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 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by