필터 지우기
필터 지우기

Drawing lines in matlab

조회 수: 1 (최근 30일)
Philipp Mueller
Philipp Mueller 2016년 12월 12일
댓글: Walter Roberson 2017년 7월 7일
Hi,
I have 3 simple questions:
1: I want draw a straight line. Ok i know its easy. I can use this command:
line([0 100],[50 50],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
But for this command i have to know "x - Start" and "x - End" point. I just want to give only the y value my command. Matlab should draw it automatically.
2: I want to draw a rectangular like in the picture but i have just one input point -> see picture... matlab should draw it automatically. Is this possible? If not, no problem
3: I want to capture the point. Is there a possibility to do that? My Input should the coordiante point (x/y) of this point and from this point i want to determine the direction ... above right/ left, below right/left.....
My Code:
clear all
clear clc
x1=[0 50 75 100]
y1=[100 75 50 25]
[xb,yb] = stairs(x1,y1);
axis([0 200 0 200])
xlim([0 150])
plot(yb,xb)
datacursormode on

채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 12일
You can use xlim() to find the current X right and left margin and pass those as the X values for line()

추가 답변 (3개)

Jan
Jan 2016년 12월 12일
1. The corrdinates of the 1st point and 1 additional component of the 2nd point are not sufficient to define a line. You need either the slope in addition or the coordinates of both points. To draw the line "automatically", the line must be defined. Therefore question 1 cannot be solved.
2. Again: What does "automatically" mean? You only need the coordinates of the vertices, then line draws the line. But Matlab cannot guess magically, where the points should appear. So how are the wanted points stored?
3. What does "capture" exactly mean?
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 1월 2일
To add text or formula use text() . To add arrows, use annotation()
Image Analyst
Image Analyst 2017년 1월 2일
What about his question 1 and 2?
And you can capture a runaway dog, or you can capture the (x,y) location where a user clicked. But I don't understand your definition of capture. Do you mean that if the user, through some unknown or other means, adds a text string to your graph that you want to detect the fact that they added something?

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


3mg4
3mg4 2016년 12월 12일
Make a line that starts way befor you need it eg from -100 to +100, then give matlab the y value and let it plot.
Use teh axis command to restricct the visible area

Arash Ebrahimi
Arash Ebrahimi 2017년 7월 7일
hello how can I draw a line in matlab with slope and a point ?
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 7월 7일
If you have the stats toolbox you can use refline()
Otherwise, use the old
y = m * x + b
where m is the slope = tan(theta) if you use angles, and b is the intercept.
If you need to solve for the intercept given a point, that is simple:
b = known_y - m * known_x

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by