필터 지우기
필터 지우기

Draw a line on a 2D plot at a particular x and y values

조회 수: 23 (최근 30일)
Orion
Orion 2014년 6월 2일
편집: Pulkit Rustagi 2020년 9월 25일
I'd like to draw a line at a particular x (and corresponding y) value for a plot that looks like this:
x=linspace(0,4)
y=x.^2
plot(x,y)
If I use the data cursor, it doesn't let me place it on a particular value (in my case where x=3), so I'd like it to do that and show me the x and corresponding y coordinates somewhere on the graph. Ideally, I'd like to have a dashed line protruding from the x and y axes to this point on the graph.
Any help would be appreciated.
Thanks

채택된 답변

George Papazafeiropoulos
George Papazafeiropoulos 2014년 6월 2일
x=linspace(0,4);
y=x.^2;
plot(x,y);
line([3;3],[0;9],'linestyle','--');
line([0;3],[9;9],'linestyle','--');
  댓글 수: 4
ARVIND KUMAR SINGH
ARVIND KUMAR SINGH 2020년 7월 6일
x=linspace(0,4);
y=x.^2;
plot(x,y);
line([3;3],[0;9],'linestyle','--','Color','red');
line([0;3],[9;9],'linestyle','--','Color','green');
Pulkit Rustagi
Pulkit Rustagi 2020년 9월 25일
편집: Pulkit Rustagi 2020년 9월 25일
Is it possible to label the said dashed line? is there a label field for line function?
Its not specificly mentioned in the documentation

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

추가 답변 (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