Plotting a mean line on a graph
63 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone
I currently have a graph that looks like this
figure plot(t,r(ix,:),'r'); hold on plot(t,r(~ix,:),'b'); xlabel('Time (ms)') ylabel('R (Y Axis)')
It is essentially a sine graph that tapers off.
What I want to do is add a line where matlab will plot the mean,
One for the value x, one for the value ~x, and one overall.
Please can someone help?
0 commentaires
Réponses (1)
jgg
le 19 Fév 2016
%set up
x = 1:0.1:10;
r = sin(x);
t = 1:91;
x = mod(t,2) == 0;
m_x = mean(r(x));
m_x2 = mean(-r(~x));
% plotting
figure
plot(t(x),r(x),'b')
hold on
plot(t(~x),-r(~x),'r')
plot(t,ones(length(t),1)*m_x)
plot(t,ones(length(t),1)*m_x2)
You can do it like this; the only operative part you need to do is:
m_x = mean(r(x));
plot(t,ones(length(t),1)*m_x)
Which in your code would like slightly different since you appear to have r as a matrix instead of a vector.
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance 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!