Finding the mean value of a set.

조회 수: 7 (최근 30일)
Erfan Parviz
Erfan Parviz 2022년 11월 9일
답변: Steven Lord 2022년 11월 9일
Let's say that I have a set of numbers, for example x= [1 2 4 6 2 7 8 4 5 7 8 9]. I want to calculate the mean value for every 3 numbers. In this case first 1 2 4 , then 6 2 7 and so on. How do I do? should I use any functions?
in fact I have a column containing 180000 numbers. and I want to calculate the mean value for every 50 numbers. Totally 180000/50=3660 mean values. I would appreciate every suggestion.

답변 (1개)

Steven Lord
Steven Lord 2022년 11월 9일
Original data:
x= [1 2 4 6 2 7 8 4 5 7 8 9]
x = 1×12
1 2 4 6 2 7 8 4 5 7 8 9
Reshape it into a 3-by-whatever matrix. I'll let MATLAB figure out what "whatever" is.
A = reshape(x, 3, [])
A = 3×4
1 6 8 7 2 2 4 8 4 7 5 9
Take the mean in dimension 1 (down the columns.)
m = mean(A, 1)
m = 1×4
2.3333 5.0000 5.6667 8.0000

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by