File Exchange

image thumbnail

Area under a curve calculation

version (2.54 KB) by Ahmed Owaid
Area can be calculated from pixels representation of the area Specially for irregular curves


Updated 01 Nov 2011

View License

from pixels representation of the area Specially for irregular curves we can find the area accurately

Cite As

Ahmed Owaid (2020). Area under a curve calculation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

俊杰 李

Abdallah Abu Aisha

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


Hi Ahmed!

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.

Ahmed Owaid

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.

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!