Find area bounded by self-intersecting array of data
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to find work from a PV diagram, thus I need to find the area bounded by my curve created by an array of data. Specifically, I need to find the area of the top enclosed curve, minus the area of the bottom enclosed curve. See the attached picture for more. I've tried using this function to find intersections of my data in order to split up the top and bottom enclosed curves but it returns ~110 intersections. I have also tried using polyarea but its giving me a result that is obviosly untrue (4*10^3), and I can't find a way for it to visually show me what area it is using in its calculations. Could anyone help me with this? Thanks!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/549863/image.jpeg)
回答(1 个)
Nipun
2024-6-7
Hi Rchamp,
I understand that you want to find the area bounded by your curve from a PV diagram, specifically the area of the top enclosed curve minus the area of the bottom enclosed curve. Here's an approach using MATLAB:
% Assuming your data is in x and y vectors
x = ...; % your x data
y = ...; % your y data
% Find the intersections of the curves
[xa, ya] = intersections(x, y);
% Split the data into two separate curves
topCurveX = x(x <= xa(1));
topCurveY = y(x <= xa(1));
bottomCurveX = x(x >= xa(2));
bottomCurveY = y(x >= xa(2));
% Calculate the areas
areaTop = trapz(topCurveX, topCurveY);
areaBottom = trapz(bottomCurveX, bottomCurveY);
% Calculate the enclosed area
enclosedArea = areaTop - areaBottom;
% Display the result
disp(['Enclosed Area: ', num2str(enclosedArea)]);
For finding intersections, you can use this function from MathWorks MATLAB File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/13351-fast-and-robust-self-intersections
Hope this helps.
Regards,
Nipun
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!