Area Under Curve and above X axis only, and between x axis limits.

36 ビュー (過去 30 日間)
Bhanu Pratap Singh
Bhanu Pratap Singh 2019 年 12 月 18 日
コメント済み: Looky 2019 年 12 月 20 日
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.
1.png
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 件のコメント
Looky
Looky 2019 年 12 月 18 日
編集済み: Looky 2019 年 12 月 18 日
The easiest solution would be to make a copy of your data and just set everything below zero to zero. The use trapz:
y=yourYData(yourXData>1&yourXData<6);
x=yourXData(yourXData>1&yourXData<6);
y(y<0)=0;
area=trapz(x, y )
Bhanu Pratap Singh
Bhanu Pratap Singh 2019 年 12 月 20 日
Yeah, that would work. Thanks a lot Looky.

サインインしてコメントする。

採用された回答

Allen
Allen 2019 年 12 月 18 日
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 件のコメント
Bhanu Pratap Singh
Bhanu Pratap Singh 2019 年 12 月 20 日
Yes, I need the threshold to be 1. I think I can do just the following, to make all values less than the threshold to be zero. Thanks a lot for helping me out.
% Set all values that are < 1 (these were originally all values less than the threshold) to zero.
y(y<1) = 0;
Looky
Looky 2019 年 12 月 20 日
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 !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by