How we can define the same number of contour vertices (points)in each level?

3 ビュー (過去 30 日間)
atefe moheyseni
atefe moheyseni 2023 年 6 月 27 日
回答済み: Mathieu NOE 2023 年 6 月 27 日
Hi there,
I used the contour function for my issue and extracted the points that made each level but the number of points(vertices) in each level is different. I need the same points in each levels, How I can define the same number of contour vertices (points)in each level?
  1 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 6 月 27 日
you could resample the data with the same number of points for all levels using interp1

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

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 6 月 27 日
hello again
this is the code I was suggesting above
now all the level lines have same number of samples N = 50 here.
if you need to have a more uniform distribution there is a bit of extra work involving transforming from cartesian to polar coordinates and resample the data in the polar coordinates system instead.
x = 0:0.1:2;
y = 0:0.1:3;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2-(Y-1.5).^2);
[cm, h] = contourf(X,Y,Z);
[contourTable, contourArray] = getContourLineCoordinates(cm);
% Fex : https://fr.mathworks.com/matlabcentral/fileexchange/74010-getcontourlinecoordinates
% Show all lines that match the kth level
hold on
for k = 5:7
levelIdx = contourTable.Level == h.LevelList(k);
x = contourTable.X(levelIdx);
y = contourTable.Y(levelIdx);
% resample the data to have always the same nb of points
N = 50;
nx = numel(x);
xi = interp1((0:nx-1)/(nx-1),x,(0:N-1)/(N-1));
ny = numel(y);
yi = interp1((0:ny-1)/(ny-1),y,(0:N-1)/(N-1));
plot(xi, yi, 'r*-', 'MarkerSize', 10)
end
hold off

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by