from pixels representation of the area Specially for irregular curves we can find the area accurately
Ahmed Owaid (2020). Area under a curve calculation (https://www.mathworks.com/matlabcentral/fileexchange/33570-area-under-a-curve-calculation), MATLAB Central File Exchange. Retrieved .
Hi Ahmed, I really like your solution. However, I am working on something very similar but for huge number of trips, so the this solution doesn't work for my case. Just wanted to ask: did you, by any chance, find a more "practical" way to find the sum of all areas between two irregular curves, or line and irregular curve ( regardless positive or negative areas)? I have been struggling finding a function/code to solve this issue but all of them return only the "net" area. Best Regards, Abdallah
Thanks for sharing your code. I've modified the values for my own use and it works perfectly well.
Small note: maybe consider replacing:
xy = print('-RGBImage');
This works as long as the function isn't called by a GUI.
Thanks ,I want to show that pixels representation can be used in area caculation when simple method fail for that specially for hysterese curves.
Oh, I see. polyarea() doesn't return what you expect for self-intersecting x-y coordinates.
Keep in mind that you don't need to save to a file then load from a file to follow your algorithm - you can grab pixels directly from the screen:
function Area = AreaUnderCurve(x,y)
minmaxXY = [min(x) max(x) min(y) max(y)];
myFig = figure('Color','w'); axis off
figIm = getframe(gca);
ratioOn = nnz(figIm.cdata==0) / numel(figIm.cdata);
squareArea = diff(minmaxXY(1:2)) * diff(minmaxXY(3:4));
Area = squareArea * ratioOn;
Is there a reason why polyarea(x,y) won't work? It seems a much simpler solution than plotting x and y, then saving the plot, then loading the saved image, then counting pixels.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!