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

3 views (last 30 days)
John Cruce
John Cruce on 7 Sep 2021
Edited: John Cruce on 2 Oct 2021
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!

Answers (1)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 7 Sep 2021
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 Comment
John Cruce
John Cruce on 13 Sep 2021
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.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!