Clear Filters
Clear Filters

Area of contor from Matrix

3 views (last 30 days)
Mad Gano
Mad Gano on 13 Jan 2023
Commented: Mad Gano on 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

Accepted Answer

Matt J
Matt J on 13 Jan 2023
Edited: Matt J on 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 Comments
Adam Danz
Adam Danz on 15 Jan 2023
Edited: Adam Danz on 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,:)

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 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

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!