How we can define the same number of contour vertices (points)in each level?
3 次查看(过去 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
2023-6-27
you could resample the data with the same number of points for all levels using interp1
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!