Transform matrices to XYZ
6 views (last 30 days)
Show older comments
Adi Purwandana
on 18 Mar 2023
Commented: Star Strider
on 19 Mar 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!
0 Comments
Accepted Answer
Star Strider
on 19 Mar 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 Comments
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!