Converting 1-D indexed array to 2-D/3-D matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Abolfazl Chaman Motlagh
am 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);
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!