Q:

calculate the average of multiple curves

I have a matrix 203559x2 which corresponds to a data of discharges curves of a battery. Knowing that each charge has about 3622 points(but it is not a fixed value), at the end I have 56 curves. I want to make an average of each 10 curves, and after that I want to overload those average curves to compare their evolutoin.
what I tried to do is to reshape the data so to have each discharge curve in a column, and than make a mean of the columns. 
here is an example of what I did:
M is a matrix 203559x2
X= reshape(M(:,1),[], 56);
Y= reshape(M(:,2),[], 56);

n=10;
for i =1:size(M,2)
    X10=mean(X(:,(1+n:2*n),2, 'omitnan');
    Y10=mean(Y(:,(1+n:n+n),2, 'omitnan');
    n=n+n
end

But I'm missing something.
I have another table M_indx is a matrix 56x2 where I have the start line and the end line of the data for each curve, but I don't know how I can use it to write this script.
any help is welcome

A:

You have several mistakes there, so I'm not sure which one is causing the problem:

203559 rows of M are not divisible to 56 columns. reshape won't invent new values for you, so M must be precisely a multiple of 56. Also, if we take the closest value 203560 which is a multiple of 56, we get 3635 rows and not 3622 as you wrote. You better check again your data to see you are not missing anything.
You for loop is overwriting X10 and Y10 on every loop. In order to save the mean from all iterations you have to use the iterator of the loop - i for indexing the output variables X10 and Y10.
You miss a closing ) on every calling to the mean function.
At the end of the loop, you write n = n+n which doubles the number of columns to take the mean of in the next iteration, while you wrote you want to take them in batches of 10.
Not sure if this how you want it - but you start from column 11, not 1 (you start n from 10, not 0).

Here is a fixed version of your code:
X = reshape(M(:,1),[], 56);
Y = reshape(M(:,2),[], 56);
X10 = zeros(size(X,1),6);
Y10 = zeros(size(X,1),6);
n = 10;
for k = 1:n:size(X,2)
    c = (k+9)/n; % column for output
    X10(:,c) = mean(X(:,k:min(k+n-1,size(X,2))),2, 'omitnan');
    Y10(:,c) = mean(Y(:,k:min(k+n-1,size(X,2))),2, 'omitnan');
end

It takes the mean of 10 columns each time and put it in one column in X10 and Y10. So X10(:,1) is the mean of X(:,1:10), X10(:,2) is the mean of X(:,11:20) and so on, and the same for Y10.
This still doesn't solve problem 1 above, that you have to figure out with your data.

