Area Under Curve and above X axis only, and between x axis limits.
32 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bhanu Pratap Singh
am 18 Dez. 2019
Kommentiert: Looky
am 20 Dez. 2019
I need to calculate the area under the curve. The curve may go down the x axis, but I dont' want to calculate that area. And then it may come up the axis again. Also, I need to calculate area in the limits of 1Hz to 6Hz, as shown in the image attached.
Please help out. I went through the trapz() function, but I don't know, how I can measure the area in this case. Thanks in advance.
2 Kommentare
Akzeptierte Antwort
Allen
am 18 Dez. 2019
If you are trying to determine the area under the curve between the frequencies of 1 Hz to 6 Hz for all y-values greater than 0, then Looky's suggestion will do the trick. However, if you are trying to determine the area under the curve between 1 Hz to 6 Hz and for all y-values greater than some threshold value other than zero, you will need to some additional adjustments before running trapz(). From the image you provided it looks like 1 V/H is your target threshold.
% Assign the y-value threshold to a variable. Makes is clearer to see how and where it is used,
% as well as makes is easy to change if needed.
thres = 1;
% Extract x- and y-data for frequencies in the desired range of 1-6 Hz.
x = yourXData(yourXData>1 & yourXData<6); % x-values in the range
y = yourYData(yourXData>1 & yourXData<6)-thres; % y-values in range & with a threshold adjustment
% Set all values that are <0 (these were originally all values less than the threshold) to zero.
y(y<0) = 0;
% Use trapz function to calculate the area under the curve.
area = trapz(x, y )
2 Kommentare
Looky
am 20 Dez. 2019
Hey Bhanu,
no, this is not the same! Just take @Allen's Solution, it has a variable threshold via the thres variable, that is what you want.
Your solution will give you the area under the curve but enclosed with x-axis and not your threshhold at 1 !
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!