How to do moving average for x and y data points in a scatter plot?

11 vues (au cours des 30 derniers jours)
I have soil moisture (x) data in the first column and correlation(y) data in the second column. I want a moving average line through the scatter plot of x and y data.I am getting a line which is connecting all the points which seems quite wrong.
Can somebody help me with this?
Thank you so much.
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 23 Avr 2023
Moving average how many points? What have you tried and what seems to be wrong?
Vidushi Koliyan
Vidushi Koliyan le 23 Avr 2023
Below is the code I used for 10 points. But it doesn't include x data. I want to see how moving average will look like with x y data.
x = DATA(:,1);
y = DATA(:,2);
plot(x,y,'xr-')
N = 8;
V = ones(1,N)/N;
Z = conv(y,V,'same')
hold on
plot(x,Z,'b-')

Connectez-vous pour commenter.

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 23 Avr 2023
Déplacé(e) : Image Analyst le 23 Avr 2023
It's not clear to me what exactly do you want to achieve.
You say 10 points, but you use N=8.
"I want to see how moving average will look like with x y data. "
Do you mean like this?
load DATA.mat
x = DATA(:,1);
y = DATA(:,2);
scatter(x,y,'xr')
N = 8;
%Moving mean of both x and y data
arr=movmean(DATA,N,1);
hold on
plot(arr(:,1),arr(:,2),'b-')
  1 commentaire
Image Analyst
Image Analyst le 23 Avr 2023
Garbage in garbage out. I think that even after smoothing the data points are unreliable. What is the time (called "x" by you instead of "t") sampling rate of this soil mosture device? What time period is it over? Milliseconds, seconds, hours, weeks, months? There seems to be little correlation between adjacent time points and I would not expect that for soil moisture unless the time points were very far apart.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Agriculture dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by