필터 지우기
필터 지우기

Connect points to the straight line

조회 수: 1 (최근 30일)
Linda Scarzanella
Linda Scarzanella 2020년 8월 27일
댓글: Star Strider 2020년 8월 28일
Hi everybody,
How can I connect the points to the straight line in the figure ?
Thanks
  댓글 수: 2
David Hill
David Hill 2020년 8월 27일
Are you talking about a stem() plot? Look at the stem() function.
Linda Scarzanella
Linda Scarzanella 2020년 8월 27일
yes, I checked and it works for me! Do you know if there's a way to show the distance from the point to the line? (or the point value, cuz I'd like to have it directly on the plot)

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

답변 (1개)

Star Strider
Star Strider 2020년 8월 27일
편집: Star Strider 2020년 8월 27일
Try this (with your own data):
x = 1:10; % Create Data
y = 2.5*rand(size(x)); % Create Data
stln = 0;
figure
plot(x, stln+zeros(size(x)), '-r') % Straight Line
hold on
plot(x, y, 'xk') % Points
plot([x; x], [zeros(size(y))+stln; y], '-g') % Connecting Lines
hold off
ptlbls = compose(' %2.1f', y);
text(x, y, ptlbls, 'HorizontalAlignment','left', 'VerticalAlignment','middle')
axis([0 11 -0.1 2.5])
Make appropriate changes to use it with your data.
  댓글 수: 4
Linda Scarzanella
Linda Scarzanella 2020년 8월 28일
The problem was that my data were an array of 10 rows and 1 column. I switched them to 1 row and 10 col. and it worked ! Thanks again!!
Star Strider
Star Strider 2020년 8월 28일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

카테고리

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