how do I average each 10 elements of a matrix?

조회 수: 7 (최근 30일)
nadia naji
nadia naji 2021년 4월 21일
댓글: Walter Roberson 2021년 4월 21일
Hi,
I have an 80x1 vector and I need to average every 10 elements from first and save them to a new vector. do you have any suggestions except for the loop? (average of first 10 elements, an average of second 10 elements, ...). thank you.

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 21일
mean10 = mean(reshape(Vector, 10, []),1)
  댓글 수: 3
nadia naji
nadia naji 2021년 4월 21일
if the vector size is not dividable by 10, it will produce an error. is it a way for this problem?
Walter Roberson
Walter Roberson 2021년 4월 21일
frame_length = 10;
Veclen = length(Vector);
num_frame = floor(Veclen/frame_length);
num_extra = Veclen - num_frame * frame_length;
frame_means = [mean(reshape(Vector(1:end-num_extra), frame_length, []),1), mean(Vector(end-num_extra+1:end)]
This code is designed so that if there are left over samples at the end, then it takes the mean of what exists.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by