Problem doing plots using contour with NaN elements in a matrix
4 次查看(过去 30 天)
显示 更早的评论
Ricardo Duarte
2021-2-15
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
The thing is:
If I do
[C,H]=contour(lon,lat,depth', [0 0])
before the depth(depth>1)=NaN it gives me a very nice contour plot. However, if I do it after the C matrix is empty.
I attached my matrices.
Thank you in advance.
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
I want to remove land from my data in order to perform further calculations where the land should not be present.
What I want is to obtain a [C H], where the C is a matrix that has the information about the area selected and that will be used to perform later a delauny triangulation.
Ricardo Duarte
2021-2-16
Yes I understand that, but supposedly the NaN are assigned to levels highers than 1 and not 0.
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
The problem is that if I don't remove it, when I perform the delauny triangulation it will take into account also the land and I don't want that. I just want triangles on the water and not on land.
dpb
2021-2-16
编辑:dpb
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
Ok, thank you very much for your help and time invested in this problem. :)
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
Ok, I will try to explain the complete problem.
I have the lon, lat, depth. With that I want to calculate the transmission loss (just at the sea) of a certain region represented by my lon, lat, depth matrices. To do so I need to define the sea level (depth=0) and remove land in order obtain my X and Y vectors and after performe the delauny triangulation. The problem here is that ,if I do not remove land before the contour, when I obtain the C matrix returned by contour, it will triangulate also in the land part and later (in the remaining part of my code) the TL will be calculated also in the land part, which is not correct.
So the code I have is:
[C,H]=contour(lon,lat,depth', [0 0]); I will use C to assing X and Y (at this stage I want to have just sea information)
X=C(1,:); Y=C(2,:);
Then I use the delauny doing this:
tri=delaunay(X,Y); (if I have land, the triangulation will be performed also in the land, which is what I don't want)
and then triplot(tri,X,Y);
And then the rest of the program...
dpb
2021-2-16
编辑:dpb
2021-2-17
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Delaunay Triangulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)