Adding vertical line to graph at certain height

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 日

1 投票

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 件のコメント

RP
RP 2019 年 8 月 26 日
Thanks a lot, this worked! However there is one caveat, I attached a picture of how it turned out. Is it possible to let the vertical line begin not at y = 0, but higher, at the lowest y level that I get if I plot the figure without the vertical line? I hope you know what I mean, it's weird to explain. If I plot the graphs without the vertical line, the y-axis starts at around 200 and I would like the vertical line just to start there. But I think it won't be possible - or is it?
Steven Lord
Steven Lord 2019 年 8 月 26 日
See the BaseValue property of s.
RP
RP 2019 年 8 月 26 日
That did it, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

RP
2019 年 8 月 26 日

コメント済み:

2020 年 3 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by