How to integrate dataset over a certain domain ?
    2 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Sumit Saha
 le 22 Avr 2021
  
    
    
    
    
    Commenté : Star Strider
      
      
 le 23 Avr 2021
            
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 ?
0 commentaires
Réponse acceptée
  Star Strider
      
      
 le 22 Avr 2021
        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 commentaires
  Star Strider
      
      
 le 23 Avr 2021
				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.  
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

