Area of contor from Matrix

2 vues (au cours des 30 derniers jours)
Mad Gano
Mad Gano le 13 Jan 2023
Commenté : Mad Gano le 18 Jan 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

Réponse acceptée

Matt J
Matt J le 13 Jan 2023
Modifié(e) : Matt J le 13 Jan 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 commentaires
Adam Danz
Adam Danz le 15 Jan 2023
Modifié(e) : Adam Danz le 15 Jan 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 le 18 Jan 2023
Thanks :)

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 13 Jan 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

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by