Moving mean of a vector with unsorted values
Afficher commentaires plus anciens
Hello everyone,
I have a vector of measured angle values (1x61 double), which was measured in this direction: 15:-1:-15 and then in the reverse direction as -14.5:1:14.5 degree. So the resulting vector is [15 14 13 ... -13 -14 -15 -14.5 -13.5 -12.5 ... 12.5 13.5 14.5]. Then I have corresponding measured Cd values for the angles, also 1x61 double.
I tried to do a moving average
Cdormov = movmean(Cd_original, 5);
When I plot the results, I can see that Matlab calculated the moving average for the Cd values as for two vectors. However, I need Matlab to treat the angle and Cd data as one X and one Y vector and calculate only one moving mean curve. How can I do this? Thank you.
The plot code:
figure(4)
hold on; grid on; grid minor;
plot(angle,Cd_original,'black-+');
plot(angle,Cdormov,'red-o');
xlabel('angle (deg)'); ylabel('Cd (-)');
legend('original data','moving mean');
title(['Cd ' name])
The plot:

Réponse acceptée
Plus de réponses (1)
You will need to interlace your data points before calling MOVMEAN. For example:
xL = +15.0:-1:-15.0;
xR = -14.5:+1:+14.5;
yL = sin(xL/4);
yR = sin(xR/4)+0.5;
yU = [yL,yR];
[xU,idx] = unique([xL,xR]);
yU = yU(idx);
yM = movmean(yU,5);
plot(xL,yL,'-+k', xR,yR,'-xk', xU,yM,'-*r')
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


