Using trapz for non-linear data points
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
yashvin
le 22 Juil 2015
Commenté : Star Strider
le 22 Juil 2015
Hello,
I have a speed vs time plot shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152378/image.png)
I want to know how acccurate is the trapz function in MATLAB for calculating the distance travelled (i.e area under the graph). Would you suggest if there is an another means of obtaining a better approximation for the area under the graph?
0 commentaires
Réponse acceptée
Star Strider
le 22 Juil 2015
I would use cumtrapz to give instantaneous distance traveled, for instance:
dist_nm = cumtrapz(airspeed, time_num);
I would create a time vector using datenum, subtracting the first value to create a realistic time vector in the context of your data:
time_num = datenum(time) - datenum(time(1));
Do the appropriate adjustments to the datenum calls if your ‘time’ data are not already in date number format.
2 commentaires
Star Strider
le 22 Juil 2015
Correct. The last value of cumtrapz is the value of the entire integral, equivalent to trapz.
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!