1
votes

I am a newbie to matlab and trying to find the area under the curve (AUC) for a part of the graph not the entire graph. I am interested to calculate separate AUC from 2 regions; one from -350 to -100 and other from -100 to +150 present on the x axis. how can I calculate AUC for these portion of the graph (not for entire x-axis)? not enough reputation to provide the figure. If someone from the community can provide a matlab code.

Every couple of values in the data set correspond to x,y coordinates. If plotted, these points generate individual (x,y) curve, where x is a fixed column from -750 to +750.
y data has N rows, something like

x = [-750:25:750];

y1 = [1.52,0.47,0.59,0.62,1.88,...];    
y2 = [1.5,0.79,0.74,1.46,0.6,...];  
y3 = [1.6,0.11,0.79,0.77,1.33,...];

yn = [0.061,0.0609,0.05948,0.0624,0.067,0.073347639,...];

...full data set not provided.

I want to calculate AUC for -350 to -100 region and from -100 to +150 region present on the x axis, for each combination of (x,y), say (x,y1), (x,y2)..

1

1 Answers

1
votes

Try something like this (using trapz):

startingIndex = find(x==-350);
endingIndex = find(x==-100);

desiredX = x(startingIndex:endingIndex);
desiredY = y1(startingIndex:endingIndex);
area = trapz(desiredX,desiredY);

As found on http://www.mathworks.com/matlabcentral/newsreader/view_thread/278102

basically it finds the index of the end points in the x array and then calcs the area under the curve from the corresponding truncated y vector.