필터 지우기
필터 지우기

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

조회 수: 26 (최근 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 CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by