how can i find mean of a plotted graph?

71 vues (au cours des 30 derniers jours)
Nikhil Murarka
Nikhil Murarka le 22 Mai 2019
Commenté : Nikhil Murarka le 24 Mai 2019
I plotted a graph in matlab and now i want to find the mean of that graph?
example:
x=linspace(0,500,7);
y=[2 4 2 6 3 8 2 ];
plot(x,y);
now i want to find the mean of this graph..what can i do this..is using mean(y) the correct way?
Thanks.
  2 commentaires
Rik
Rik le 22 Mai 2019
Probably, since the mean function can be used to calculate the mean of an array. Do you mean you want the average of the plotted datapoints, or do you want something else?
Nikhil Murarka
Nikhil Murarka le 22 Mai 2019
I want to find the average value of the resultant graph.Mathematically i can find the net area inclosed by the graph and divide by the range of x and i get the mean value..but how do i do it in matlab.

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 22 Mai 2019
The thing you are asking is slightly different from what is generally meant with 'mean'. The code below shows two interpretations. The mean approach assumes equal weight of all data, while the graph approach will give less weight to the two edge values. (and the graph approach has better support for unequally spaced data)
x=linspace(0,500,7);
y=[2 4 2 6 3 8 2 ];
%ensure a sort based on x
[x,order]=sort(x);
y=y(order);
%convert x,y data to a closed polygon
xc=[x x(end) x(1)];
yc=[y 0 0 ];
A=polyarea(xc,yc);
mu=A/(x(end)-x(1));
figure(1),clf(1)%only use clf in debugging
h_patch=patch(xc,yc,'c');hold on
h_data=plot(x,y,'b*');
legend([h_data h_patch],{'data','area'},...
'Location','NorthWest')
title({sprintf('average height of shaded area: %.1f',mu),...
sprintf('average height of data points: %.1f',mean(y))})
  1 commentaire
Nikhil Murarka
Nikhil Murarka le 24 Mai 2019
Thanks for the Answer!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by