How to integrate dataset over a certain domain ?

조회 수: 2 (최근 30일)
Sumit Saha
Sumit Saha 2021년 4월 22일
댓글: Star Strider 2021년 4월 23일
clear all
close all
clc
load data.txt
S_v = data(:,2);
T = data (:,1);
I_H = trapz(S_v); %Spectral_Intensity
Here it integrates over the whole domain. But how can I integrate within the specified range ?

채택된 답변

Star Strider
Star Strider 2021년 4월 22일
Perhaps:
load data.txt
S_v = data(:,2);
T = data (:,1);
Trange = (T >= 0.1) & (T <= 2.5);
I_H = trapz(T(Trange), S_v(Trange)); %Spectral_Intensity
will do what you want. (Not able to test it without ‘data.txt’.)
Do not use clear or clc. It is simply inefficient.
  댓글 수: 2
Sumit Saha
Sumit Saha 2021년 4월 23일
@Star Strider Thank you so much. I just want to ask that for such integration using trapz command is completely okay? Because I'm calculating all these things for earthquake engineering.
Star Strider
Star Strider 2021년 4월 23일
As always, my pleasure!
With vectors or arrays, the trapz funciton is the only option. The other integration functions require function handle arguments, and integrate the functions themselves between specific limits.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by