필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by