Area of contor from Matrix

4 次查看(过去 30 天)
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

采纳的回答

Matt J
Matt J 2023-1-13
编辑:Matt J 2023-1-13
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 个评论
Adam Danz
Adam Danz 2023-1-15
编辑:Adam Danz 2023-1-15
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,:)

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-1-13
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

类别

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