How do I calculate the partial area under a curve with MATLAB?

不问归期 提交于 2019-12-11 12:55:37

问题


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:


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.



来源:https://stackoverflow.com/questions/30494578/how-do-i-calculate-the-partial-area-under-a-curve-with-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!