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
0 个评论
采纳的回答
Matt J
2023-1-13
编辑:Matt J
2023-1-13
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
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
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
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!