Borrar filtros
Borrar filtros

Area of contor from Matrix

3 visualizaciones (últimos 30 días)
Mad Gano
Mad Gano el 13 de En. de 2023
Comentada: Mad Gano el 18 de En. de 2023
I have a matrix with 2 coordinates x, y and the force F
about 2 million rows (2M X 3)
I want to plot the contor of this data while F > 0.1 N.
after that I want to calculate the area of the contor.
I can't use the function "contour" because I don't have mesh data and I cant use meshgrid because the matrix is very large
Can any one help me :)
Thanks

Respuesta aceptada

Matt J
Matt J el 13 de En. de 2023
Editada: Matt J el 13 de En. de 2023
Use scatteredInterpolant to resample the data on a grid,
S=scatteredInterpolant(x,y,F);
xg=linspace(min(x),max(x),500);
yg=linspace(min(y),max(y),500);
Fg=S({xg,yg});
and then use contour().
cm=contour(xg,yg,Fg',[0.1,0.1]);
meshgrid is irrelevant to the discussion. As demonstrated above, you don't need meshgrids of the x,y data to use contour(), but even if you were to do that, they wouldn't be that large.
  4 comentarios
Adam Danz
Adam Danz el 15 de En. de 2023
Editada: Adam Danz el 15 de En. de 2023
getContourLineCoordinates produces a table indicating the (x,y) coordinates and level for all contourlines along with a grouping variable that groups each contour line group. You can loop through the groups to compute the area for each contour line and then select the largest group.
File=load('TestFile.mat');
x=File.Matrix(:,1);
y=File.Matrix(:,2);
F=File.Matrix(:,3);
S=scatteredInterpolant(x,y,F);
xg=linspace(min(x),max(x),500);
yg=linspace(min(y),max(y),500);
Fg=S({xg,yg});
cm=contour(xg,yg,Fg',[0.01,0.01]);
T=getContourLineCoordinates(cm); % Get contour table
% loop through each contour group
groups = unique(T.Group);
areas = nan(size(groups));
for i = 1:numel(groups)
idx = T.Group==i;
areas(i) = polyarea(T.X(idx), T.Y(idx));
end
% Find the max area
[maxArea, maxidx] = max(areas)
Returns
maxArea =
9.371e-05
maxidx =
1
The largest area is 9.371e-05 which is in the first index which is group groups(i)=1.
To isolate info about that contour line from the table ,
TLargest = T(T.Group==1,:)
Mad Gano
Mad Gano el 18 de En. de 2023
Thanks :)

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 13 de En. de 2023
See https://www.mathworks.com/matlabcentral/fileexchange/38858-contour-plot-for-scattered-data?focused=5249779&tab=function and notice the code needs to build the triangulation first before calling the function

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by