Transform matrices to XYZ

6 ビュー (過去 30 日間)
Adi Purwandana
Adi Purwandana 2023 年 3 月 18 日
コメント済み: Star Strider 2023 年 3 月 19 日
Hello,
I have a mat file containing 3 variables connected each other:
lon --> 19200x1 double
lat --> 9600x1 double
depth --> 9600x19200 double
I want to create an XYZ format (column X for lon; column Y for lat; column Z for the depth value for respected lon and lat value). So that each lon-lat has respected depth value. Does anyone know how to do that?
Thank you for your attention!

採用された回答

Star Strider
Star Strider 2023 年 3 月 19 日
Something like this should work —
[Lat,Lon] = ndgrid(lat,lon);
LatLonDepth = [Lat(:) Lon(:), depth(:)];
Since I do not know how the ‘depth’ matrix was created, this could also be appropriate:
[Lat,Lon] = meshgrid(lat,lon);
LatLonDepth = [Lat(:) Lon(:), depth(:)];
You will need to determine which is most appropriate. The ndgrid and meshgrid functions create their matrices differently, so one result will be correct and the other will not. You will need to determine that. If you know which one was used to calculate the ‘depth’ matrix, then choose that function. If you do not, it will be necessary to see which one accurately assigns the correct ‘lat’ and ‘lon’ values to the correct ‘depth’ value.
The (:) subscript operator creates column vectors from the corresponding matrices. They should all have the same row sizes.
.
  2 件のコメント
Adi Purwandana
Adi Purwandana 2023 年 3 月 19 日
Really answering my question...Thank you!
Star Strider
Star Strider 2023 年 3 月 19 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by