필터 지우기
필터 지우기

How do I return The Average of particular row incriment in a vector?

조회 수: 2 (최근 30일)
Arief Yoga Randytama
Arief Yoga Randytama 2021년 4월 22일
댓글: Jonas 2021년 4월 22일
Hi, suppose i want to return vector B which is the average of the first n column of a vector A and the next n and so on. What should the algorithm be? For example here i take n=3, The vector A is the input, and B is the desired result. Thanks!
A = [1 1 1 2 2 2 5 5 8]
B = [1 2 6]
  댓글 수: 1
Jonas
Jonas 2021년 4월 22일
you could reshape you vector to a matrix using reshape, then calculate the mean along the dimension in which reshape puts the elements (dont know at the moment of reshape fills row by row or column by column)

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

답변 (1개)

the cyclist
the cyclist 2021년 4월 22일
A = [1 1 1 2 2 2 5 5 8];
n = 3;
B = mean(reshape(A,n,[]))
B = 1×3
1 2 6

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by