Converting gridded elevation data and x, y coords into row output

We are dealing with UTM coords here, and we have: Northings, Eastings, and gridded Elevation-values.
dimensions--
x is 1x30
y is 1x41
z is 41x30
Currently this meshes well into a surface.
How can I export this data into rows of:
x1, y1, z1;
x2,y2,z2;
....
xend,yend,zend
?

3 Comments

Thanks so much. Matlab is really akin to an onion with all too many layers!
Here's a followup...
Do you know if there is a way to have contour outputs at certain z values? E.g., somehow setting z = 0 and finding all x,y coords that intersect that plane? I'm guessing there would have to be interpolation involved?
You can pass a level list to contour() . If you are only passing one value, then the trick is to pass it twice:
contour(x, y, z, 2) %asks for two contours
contour(x, y, z, [2 2]) %asks for a contour at z = 2
Interpreting the contour matrix that you can return from contour() is a nuisance. There are some File Exchange submissions that make it easier.

Sign in to comment.

 Accepted Answer

Not sure I understand your question.
[X,Y]=meshgrid(x,y);%assume this is what you want
data=[X(:),Y(:),z(:)];

5 Comments

Fast!
that creates a big matrix: 1230x3
Is there a way to remove NaN values from the output to decrease the number of rows to having data only?
Do you have entire rows that are nan that you want to delete? Or any row the has a nan value within the row?
[idx,~]=find(isnan(data));
data(idx,:)=[];
With new enough MATLAB you could
rmmissing(data)
if you wanted to remove any row that has one or more nan.
Good Work -- David and Walter... much appreciated.

Sign in to comment.

More Answers (0)

Products

Release

R2020a

Asked:

on 20 Sep 2020

Commented:

on 23 Sep 2020

Community Treasure Hunt

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

Start Hunting!