Plotting a mean line on a graph

79 visualizaciones (últimos 30 días)
Om
Om el 19 de Feb. de 2016
Respondida: jgg el 19 de Feb. de 2016
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?

Respuestas (1)

jgg
jgg el 19 de Feb. de 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.

Categorías

Más información sobre Directed Graphs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by