MATLAB Answers

Create array with integral values

25 views (last 30 days)
Hi everyone,
i have a vector of 3366 elements. Basically i have a nan value every 66 elements. I want to create a new vector that cointains the integration (trapz) of the first 66 elements as the first value, than the integral from the 68 to the 134 as the second value and so on. How can this be achivied ? Could anyone please help me ?

Accepted Answer

the cyclist
the cyclist on 9 Feb 2021
Edited: the cyclist on 9 Feb 2021
% original vector
v = rand(1,3366);
r = reshape(v,66,[]);
% You may need to do a step where you remove the last row of r, which has the NaNs.
r(end,:) = [];
trapz(r)
ans = 1×51
30.6321 30.0928 30.3872 27.5168 32.7206 26.7639 33.0282 31.8406 35.3154 29.4117 36.6030 32.3742 34.9626 31.9944 30.6600 33.6818 33.8455 31.0136 31.2125 32.2833 32.6725 30.4109 31.4081 31.9513 30.2909 32.1654 34.3995 32.8930 33.0413 33.6475
  3 Comments
Francesco Primerano
Francesco Primerano on 10 Feb 2021
You're right, thank you so much, what tricked me was the fact that values were stored as 1 row and x columns instead of one column and x rows. Thanks again man

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!