Transform matrices to XYZ

6 次查看(过去 30 天)
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by