필터 지우기
필터 지우기

How to average in rows of two numbers

조회 수: 3 (최근 30일)
Lokeswara reddy pamulapate
Lokeswara reddy pamulapate 2020년 3월 7일
댓글: Star Strider 2020년 3월 8일
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

채택된 답변

Star Strider
Star Strider 2020년 3월 7일
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
Lokeswara reddy pamulapate
Lokeswara reddy pamulapate 2020년 3월 8일
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 2020년 3월 8일
I am lost.
xm = filter([1 0 0 1], 2, x(1:153)); % Column Mean

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by