How do I access z coordinates in a contour map?
15 views (last 30 days)
Show older comments
I've made a contour map of sand particles and I basically need to access the z coordinates of the particles. In order to do this I'm trying to draw rectangles around each particle and then find the z coordinates within the rectangle. I can draw the rectangles with no problem but I have no idea how to access the z coordinates.
0 Comments
Answers (1)
Cam Salzberger
on 25 Jul 2017
Hey Neal,
If you are using the Data Brush to draw the rectangles, I'm not sure that will do anything for you with contour plots. If you are making something yourself with ginput or something else, then that's fine.
You can get access to the contour object a couple different ways, but the easiest to me is just:
hAx = gca; % Get handle to the current axes
hCon = hAx.Children; % Assuming there's just a contour plot on the axes
You can access the full matrix of z-values that was used to generate the contour plot through:
hCon.ZData
Now, depending on how you've drawn your rectangle, I'm assuming you can at least get limits of the rectangle? If you can get something equivalent to the xmin, xmax, ymin, and ymax of the rectangle, you could do something like this with logical indexing:
ptsWithinRect = hCon.XData >= xmin & hCon.XData <= xmax & hCon.YData >= ymin & hCon.YData <= ymax;
zDataWithinRect = hCon.ZData(ptsWithinRect);
-Cam
2 Comments
Cam Salzberger
on 4 Aug 2017
You may be doing something differently with your drawing of the rectangle or determining of which points are within the rectangle. Can you post sample code (if you're still running into this issue)?
See Also
Categories
Find more on Contour Plots 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!