Integral average of y values with respect to x values

Illustration
Sophia - 2021-02-10T11:11:02+00:00
Question: Integral average of y values with respect to x values

I have two vectors (x and y) of the same size with x having more than one value in the y direction. For example, x is [0.02 0.02 0.03 0.03 0.03 0.04 0.04 0.05 0.05 0.05] and y is [0.23 0.40 0.12 0.16 0.09 0.50 0.02 0.33 0.10 0.08]. I want to convert the attached scattered plot of the two vectors to a simple continuous curve, by evaluating the integral average of y values with respect to x values. Take into account that the x vector is already ordered from small to large values. How could I do this?

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

I’m not exactly certain what you want, but one approach would be to use the cumtrapz function:
 
 
x = [0.02 0.02 0.03 0.03 0.03 0.04 0.04 0.05 0.05 0.05];
y = [0.23 0.40 0.12 0.16 0.09 0.50 0.02 0.33 0.10 0.08];

I = cumtrapz(x,y);                      % Integrated Vector Of ‘y’ w.r.t. ‘x’

figure(1)
plot(x, I)
grid


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!