How can i integrate an array using the trapz function

If i have the following data
time=[1 2 3 4 5] %time in seconds
acceleration=[1.1 1.2 1.3 1.4 1.5]
Then how can I integrate acceleration and get the velocity at every second in the form of an array.
I tried v=trapz(acceleration);
but that just integrates acceleration and returns a single value

 Accepted Answer

Torsten
Torsten on 3 Mar 2023
Moved: Torsten on 3 Mar 2023
Use cumtrapz instead.

3 Comments

is there a way the trapezoidal rule can be applied to each 2 elememts
So basically it integrates the first 2 elements when theyre plotted against time, then the next 2 elements and so on
Believe me: cumtrapz(time,acceleration) gives you the velocity field V with initial value V(time(1)) = 0.
If you do
(second element-first element)/time
you differentiate. But velocity is acceleration integrated.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!