Problem doing plots using contour with NaN elements in a matrix
古いコメントを表示
Dear all,
I have 3 matrices: lon, lat, depth.
Than I want to remove all the depth values that are bigger than 0. To do so I use:
depth(depth>1)=NaN.
By doing this I remove the land part, which is ok.
The problem then is that I want to create a contour arround the sea level, which means at the depth =0. To do so I'm doing:
[C,H]=contour(lon,lat,depth',[0 0]);
As a result I obtain an empty C matrix and I don't understand why!!!
Hope you can help me!
Thanks in advance.
16 件のコメント
dpb
2021 年 2 月 15 日
That would appear to indicate your resulting data don't have any zero values...not sure anybody here could do anything w/o the Z data.
Ricardo Duarte
2021 年 2 月 15 日
編集済み: dpb
2021 年 2 月 15 日
dpb
2021 年 2 月 15 日
So, what is it you are trying to do here, anyways? Why are you setting to NaN, anyway?
What's wrong with the returned contour for level==0 from the original array?
Ricardo Duarte
2021 年 2 月 15 日
dpb
2021 年 2 月 15 日
Well, that's still the same contour.
One can't interpolate across a NaN.
Ricardo Duarte
2021 年 2 月 16 日
dpb
2021 年 2 月 16 日
Yes, but there isn't necessarily a crossing with a value between 0 and 1 everywhere for contour to be able to find a closed path.
Again, you want the best estimate of what the zero-level contour is; you don't need to remove data to do that; in fact, you've demonstrated that doing so prevents you from finding that contour level.
Ricardo Duarte
2021 年 2 月 16 日
Find the contour first, THEN triangulate. If you have to remove the positions that are >0 then, so be it, but still the countour locations will have been determined and returned in the countour object.
Again, the countour is a boundary; you've got to have something that can be interpolated across the zero plane for countour() to be able to figure out where that is. When you have something that is like [-1.234 NaN] in one direction; what's it supposed to do? There simply is no way to infer where zero is between those two values.
As is, you're not removing all land, anyways, by using the >1 level; you probably will be better served to leave completely alone and find the zero contour object, then remove everything above 0.
I'm not sure what you're doing with the contour object, anyhows???
I've never messed with the guts of contour much other than recollect digging into the convoluted storage pattern of the returned contour object array for somebody here once upon a time to help them retrieve information from it, but having done is all that I do remember.
Ricardo Duarte
2021 年 2 月 16 日
dpb
2021 年 2 月 16 日
What are you trying to triangulate over? How do you try to combine the returned contour path with the remainder of the image that doesn't have anything excepting the elevations in it?
It's just not clear what your next step you're trying to do is -- I'm sure there's a way forward, just need more input on what your end objective really is here.
Doesn't help I don't have any of the mapping toolsets, sorry...
Ricardo Duarte
2021 年 2 月 16 日
You have to determine from the contour what is inside and what is outside the sea/land boundary. Removing values >0 from the depth matrix doesn't affect that; in fact by removing those you'll just make estimates of where those are less precise than will be otherwise.
I don't think the basic MATLAB delaunay function knows about how to handle holes automagically and I've not used it enough to know just how one would go about representing the connection points to do this. The routines are for convex polygons.
There is one example of setting constraints for a nonconvex polygon, but even it doesn't actually have a hole in the middle of it; it is roughly a J-shaped polygon.
All in all, I'm not so sure MATLAB is equipped to handle the problem...then again, I didn't DAGS for other examples, either.
dpb
2021 年 2 月 16 日
A search uncovered a response from Bruno that pointed another user to <mesh2d-delaunay-based-unstructured-mesh-generation> on File Exchange
Ricardo Duarte
2021 年 2 月 16 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!