How to average in rows of two numbers

7 visualizaciones (últimos 30 días)
Lokeswara reddy pamulapate
Lokeswara reddy pamulapate el 7 de Mzo. de 2020
Comentada: Star Strider el 8 de Mzo. de 2020
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

Respuesta aceptada

Star Strider
Star Strider el 7 de Mzo. de 2020
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
  4 comentarios
Lokeswara reddy pamulapate
Lokeswara reddy pamulapate el 8 de Mzo. de 2020
I am getting the result, but I only need 153 values out of 305, I want the average of two numbers in one. that is 1st column to 4th column is one value which is stored in 1st column and 2nd column to 5th column is one value which is stored in 2nd column and 3rd column to 6th column is one value which is stored in 3rd column and 7th column to 10th column is one value which is stored in 4th column and 8th column to 11th column which is one value which is stored in 5th column and 9th column to 12th column which is one value which is stored in 6th column and 13th column to 16th column is one value which is stored in 7th column and 14t column to 17th column is one value which is stored in 8th column and 15th column to 18th column is one value which is stored in 9th column and soo on.
I want the average of 1st three columns values to 2nd three columns and the 2nd three must not be taken again and next I want to take average of values from 7,8,9 to 10,11,12 and next 13,14,15 to 16,17,18 in this way I will get the average of values in a matrix value 1*152 like that.
Star Strider
Star Strider el 8 de Mzo. de 2020
I am lost.
xm = filter([1 0 0 1], 2, x(1:153)); % Column Mean

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by