Filter löschen
Filter löschen

Transform matrices to XYZ

6 Ansichten (letzte 30 Tage)
Adi Purwandana
Adi Purwandana am 18 Mär. 2023
Kommentiert: Star Strider am 19 Mär. 2023
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!

Akzeptierte Antwort

Star Strider
Star Strider am 19 Mär. 2023
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 Kommentare
Adi Purwandana
Adi Purwandana am 19 Mär. 2023
Really answering my question...Thank you!
Star Strider
Star Strider am 19 Mär. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by