Drawing lines in a loop

Dear all,
I am searching for a way to draw multiple lines in a "for", or "while" loop. This is what I tried so far:
plot(xa,phi(xa),'b',x,eta(x),'b')
hold on
syms xls yls
yls = 0.004;
xls = 0.0001;
while xls ~= width,
startp = [xls yls];
endp = [xls eta(xls)];
Xl = [startp(1) endp(1)];
Yl = [startp(2) endp(2)];
line(Xl, Yl);
xls = xls + 0.0001;
end
As you can see, I am trying to draw vertical lines in a plot showing a function. These vertical lines should end exactly where they intersect the function...
I am quite stuck with this problem and I would very much appreciate it if someone could help me!
Kind regards, Marc

1 件のコメント

the cyclist
the cyclist 2013 年 7 月 14 日
I can't run your code, so I can't actually see the problem exhibited. Can you please describe in more detail what the actual problem is?

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 14 日

0 投票

%Example
close
x=0:0.1:10
y=sin(x)./(x+0.1)
plot(x,y)
hold on
x_line=[0 2 4 6 8 10] % The x coordinate intersecting the vertical lines
y_line=interp1(x,y,x_line)
y_lim=get(gca,'ylim');
ymax=y_lim(2);
for k=1:numel(x_line)
plot([x_line(k),x_line(k)],[y_line(k) ymax],'r')
end
hold off

1 件のコメント

Marc
Marc 2013 年 7 月 14 日
thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by