フィルターのクリア

How to access the data of contourf function to decides whether the interior of the contour is filled or not?

4 ビュー (過去 30 日間)
How can I access the contourf function data that could inform me on whether the internal data of the contour (that has a filled colour) is greater or lesser than the value the contour is designated to 'cut' the surface function at.
I.e.
p = peaks;
figure
k = contourf(p, [2 2]);
The 'cut' of the surface function, p, occurs at a defined value (or you could think of it as a height) of 2. This would give a plot as follows:
To restate my question; how/where can I access the data that dictates if the internal value of the contour is greater or lesser than the cut off value (in this case, 2). In this case it is clear that the internal value is greater than the cut off value, but I would like to access this information so that can create an algorithm to do this autonomously for any contourf plot. I am confident this information should be availible as the contourf function knows whether to colour fill the interior of the contour or not.
Thank you for any advice in advance.

採用された回答

darova
darova 2020 年 3 月 4 日
You can access to each contour separately
[C,h] = contourf(p, [2 2]);
h1 = get(h,'children');
for i = 1:length(h1)
x = get(h1(i),'xdata');
y = get(h1(i),'ydata');
end
  9 件のコメント
darova
darova 2020 年 5 月 14 日
Sorry fot the late response. Didn't see you answered
What about inpolygon? It can check if point is inside a contour
Elliot Bontoft
Elliot Bontoft 2020 年 5 月 19 日
Hi @darova,
Thanks for getting back to this post.
Yes, in the end I used the first three points, calculated the angle between the vector from point 2-1, and 2-3. Then took a small step in the vector of half that angle in either direction (thus, one must be inside and one outside).
Knowing this, I used inpolygon to check which one was internal.
Thanks for your help, this is working well and is quite robust.
Code attached.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by