How we can define the same number of contour vertices (points)in each level?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
atefe moheyseni
el 27 de Jun. de 2023
Respondida: Mathieu NOE
el 27 de Jun. de 2023
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 comentario
Mathieu NOE
el 27 de Jun. de 2023
you could resample the data with the same number of points for all levels using interp1
Respuesta aceptada
Mathieu NOE
el 27 de Jun. de 2023
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!