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!
댓글 수: 0
답변 (1개)
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);
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!