Adding vertical line to graph at certain height

조회 수: 34 (최근 30일)
RP
RP 2019년 8월 26일
댓글: John Navarro 2020년 3월 29일
Hi everyone,
I attached a picture of what I want to achieve - I'm using a script with a loop that creates a plot for each participant in a study and would like to add a vertical line at 4.5 seconds. I did manage to add a vertical line using
x=[4.5,4.5];
y=[-10,0];
plot(x,y)
However the problem is that I need to specify y-values. This is a problem because the y scale can differ vastly between participants (for some it will be 600 - 700, for some 0 - 10). Is there a universal way to add a line that simply starts at the bottom (at the x-axis) and goes up to a certain y-value? Thank you in advance!

채택된 답변

Steven Lord
Steven Lord 2019년 8월 26일
I'd use the stem function. First, generate some sample data and plot it. Turn hold on so we can add the stem plot later.
x = 1:10;
y = x.^2;
plot(x, y, '-');
hold on
For the selected stem locations, determine the corresponding y values.
xx = 2:1.75:9;
yy = interp1(x, y, xx);
Plot the stems.
s = stem(xx, yy);
You can adjust various properties of the stems using s. For instance, to make the markers larger magenta squares:
s.Marker = 's';
s.MarkerSize = 12;
s.MarkerFaceColor = 'm';
  댓글 수: 3
Steven Lord
Steven Lord 2019년 8월 26일
See the BaseValue property of s.
RP
RP 2019년 8월 26일
That did it, thank you!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by