plot 3 horizontal lines

조회 수: 1 (최근 30일)
Chris
Chris 2011년 8월 23일
편집: John D'Errico 2023년 7월 12일
I have a simple x,y plot of values. I want to plot 3 additional horizontal lines, one being the mean, one being 2 standard deviations above, and one being 2 standard deviations below. I figured out how to plot the mean but I can't figure out how to plot the standard deviations on the same plot.

채택된 답변

Vishnu
Vishnu 2023년 7월 12일
Hey @Chris!
I see that you want to create a plot with horizontal lines representing values above and below the mean by 2 standard deviations. Here is an example oh how we can achieve this:
A = [4 5 1];
t = [1 2 3];
plot(t,A)
hold on
avg = mean(A);
deviation = std(A);
yline(avg,"g")
yline(avg+2*deviation,"r")
yline(avg-2*deviation,"b")
hold off
Note the hold on and hold off is used to keep plotting onto the same plot. for further reading you can check out the following documentations:
  댓글 수: 1
John D'Errico
John D'Errico 2023년 7월 12일
편집: John D'Errico 2023년 7월 12일
I accepted this accurate answer, since the question was an old one and might not get seens by the OP.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by