MATLAB: How to average in rows of two numbers

averageaverage of rowsaveragingaveraging rowsaveraging the rowshelp

Hi all,
I have a matrix of 1*305, I want to take the average of two rows like (1st row to 4th row) and (2nd row to 5th row) and (3rd row to 6th row) and (7th row to 10th row) and (8th row to 11th row) and (9th row to 12 row) and soo on. I want to take average in this way, can anyone help me out.
Thankyou

Best Answer

If I understand correctly what you want to do, this will work:
D = load('AI_Aorta.mat');
x = D.x;
idx = hankel(1:4, 4:numel(x)); % Index Matrix
xm = mean(x(idx)); % Mean Of Columns Of Resulting Matrix
To understand what this code does and how it works:
Check_First_Five_Columns = x(idx(:,1:5)) % The 'xm' Variable Is The Mean Of The Columns Of This Matrix (Extended To 302 Columns)
producing:
Check_First_Five_Columns =
0.1247 0.2370 0.1695 0.2010 0.2228
0.2370 0.1695 0.2010 0.2228 0.1482
0.1695 0.2010 0.2228 0.1482 0.1683
0.2010 0.2228 0.1482 0.1683 0.2063