how to calculate the average of two values data that side by side and place it between those two values

조회 수: 1 (최근 30일)
i want to calculate the average of two values data that side by side and placed it between those two values after that, the last values data will be divided by 2 and placed at the end of the array
for example, if i have
A=[4 2 8 10 6]
then the average of those data that side by side is [3 5 9 8]
after that, the last values of A (=6) will be divided by 2 and equal 3
then i want it to become
B=[4
3
2
5
8
9
10
8
6
3]

채택된 답변

darova
darova 2020년 2월 26일
편집: darova 2020년 2월 26일
Use interp1
A=[4 2 8 10 6];
x = 1:length(A); % 1 2 3 4 5
xx = linspace(x(1),x(end),length(A)*2-1); % 1 1.5 2 2.5 3 3.5 4 4.5 5
A1 = interp1(x,A,xx);
plot(x,A,'.-r')
hold on
plot(xx,A1,'ob')
hold off
A1(end+1) = A1(end)/2; % just divide last element

추가 답변 (0개)

카테고리

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