Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Dear Sirs, would you please help me and tell me how can I plot the average value of the previous y, while we have thousands (x, y) versus the current X?
1 回表示 (過去 30 日間)
古いコメントを表示
(xn, yn), yn=(sigma (i=1) to (i=n) [yn])/n
output(xn, yn=average of previous y and the current y)
We have thousands of dots like (xn, yn), but the number of our data is accidental and it changes by time of sampling. So, there is a necessity to have dynamic code. I think it is not so difficult. Before anything, I am so grateful for your helping. Thank you so much.
4 件のコメント
回答 (2 件)
John D'Errico
2018 年 4 月 30 日
編集済み: John D'Errico
2018 年 4 月 30 日
If you just have a vector X and a vector Y, and you want to plot the average of all preceding Y as a function of X, this is trivial and easy to do efficiently.
% some garbage data
N = 10000;
X = rand(1,N);
Y = X + randn(size(X));
[X,sorttags] = sort(X);
Y = Y(sorttags);
% The average of all preceding Y, including the current Y
Ymean = cumsum(Y)./(1:N);
plot(X,Ymean,'.')
WTP?
Or, if you don't want to include the current element in that average...
plot(X(2:end),Ymean(1:end-1),'.')
Or, if you just want the average of the last 10 elements...
Ymean10 = conv(Y,ones(1,10)/10,'valid');
plot(X(10:end),Ymean10,'.')
It would be slightly more difficult if you wanted the mean of only those elements within a specified distance in X less than the current point, because then the number of elements in those means will vary.
3 件のコメント
John D'Errico
2018 年 5 月 1 日
編集済み: John D'Errico
2018 年 5 月 1 日
N = length(X);
WTP? If you have the data, then you can determine the length of the data.
Jon
2018 年 4 月 30 日
If you do not want to keep all of the y's in memory and are only interested in the average of all of the y's up to the current sample (N+1) you can do this recursively as: ybar = n/(n+1)*ybar + y/(n+1)
Where ybar is the next value of the average, and n is the total number of point obtained so far. So in this case you just have to keep track of two scalar values, the count n, and the last value of the average, ybar
12 件のコメント
Walter Roberson
2018 年 5 月 2 日
Sorry, I do not use Excel on Windows. But see also https://www.mathworks.com/matlabcentral/answers/275384-xlswrite-error-worksheet-could-not-be-activated
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!