Definite integral over discrete data
古いコメントを表示
Hi, I have a set of discrete data "A" over frequency "f". I want to integrate "A" over "f" from "f1" to "f2". I don't want to integrate over all frequency range. Using trapz(f,A) it gives me the integral over all frequencies... How can I do that? -Thank you
採用された回答
その他の回答 (1 件)
trapz( f( startIdx:endIdx ), A( startIdx:endIdx ) )
where startIdx and endIdx are the indices of the frequencies f1 and f2 which you can find by e.g.
startIdx = find( f >= f1, 1 ); endIdx = find( f >= f2, 1 );
if you don't already have them. I use >= there because exact equality tests are not stable with doubles, but you can change the test there to whatever you prefer.
4 件のコメント
Adam
2015 年 11 月 25 日
How did my answer end up being marked as spam?!
Star Strider
2015 年 11 月 25 日
You just lucked out!
This happens to us all from time to time, and requires someone else to rescue the post. There have been repeated requests that for those above a certain number of reputation points a post would never be flagged by the spam trap, but we’ve been unsuccessful in getting it implemented.
I’ll rescue it.
Adam
2015 年 11 月 26 日
Thanks! I've never come across it before.
Star Strider
2015 年 11 月 26 日
My pleasure! You will if you post often enough, although the spam trap has gotten progressively more sophisticated since the spam inundations in the Spring of 2014.
There should be a link on the spam notice you see that tells you to contact MathWorks if you believe the spam trap flagged it erroneously. I always click on it and include the URL of the post in my message, although I suspect several people with privileges to do so see the false positive and remove it, as I did with yours.
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!