Plotting a mean line on a graph
83 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
jgg
2016 年 2 月 19 日
%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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!