MATLAB Answers

Matrix integral over layers

2 views (last 30 days)
Lev Mihailov
Lev Mihailov on 17 Jul 2020
Answered: Bjorn Gustavsson on 17 Jul 2020
Hello! I have a matrix in it the number of steps per time. Is it possible to integrate each column of the matrix layer by layer (layer sizes may differ)
layer=(1:5:30); % for example, I took layer 5 (but it can change)
% trying to create a loop for layers
for i=1:length(layer)-1
it gives me only one value
Lev Mihailov
Lev Mihailov on 17 Jul 2020
yes, I want such overlaps

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 17 Jul 2020
For this I would try cumtrapz - it calculates the cumulative (sp?) trapezoidal integral in the same manner as cumsum calculates the cumulative sum along an array. Doing that would give you the cumulative integrals of your matrix with the same size as your matrix. That way you can easily calculate every following integral between 2 boundaries from that one just by taking the difference between the corresponding boundary-elements. Something like this:
I = peaks(40);
I = I(1:30,:);
ciI = cumtrapz(I);
i10to17ofI = ciI(17,:) - ciI(10,:);


Community Treasure Hunt

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

Start Hunting!

Translated by