What is the general coding for drawing a line in matlab? For this one project I have to draw a circle and then draw multiple lines that will connect points on the circle. Is this possible and if so how can I accomplish this?
How do you draw a line segment in matlab?
The easiest way to do this is with matlab's plot, so you have to generate arrays of points to plot.
To do this, you start with your x-axis (x = -4:.1:4; for instance) and then set other variables equal to equations of x, i.e. y = 2*x.
Then call plot(x,y). So that you can plot multiple curves on x, you need to call hold on so that it keeps the previous plots. Here is an example:
radius=4
X = -radius:0.1:radius;
Y = sqrt(radius^2-(X.^2));
plot(X,Y)
Y2 = -Y;
hold on;
plot(X,Y2);
%the above plots your circle
%Now say you want a line segment from 2 point on the circle,
%either build it with linear equation y_ls=m*x+b OR
%just plot the points, and matlab will connect them for you:
plot([X(4) X(20)], [Y(4) Y2(20)]);
You can copy paste this code and see how it works...
Just remember a nice feature of matlab is you can type "help command" where for any command i.e. "help plot" to get more information on how to use it.
Alternatively check out matlab function reference:
http://www.mathworks.com/access/helpdesk...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment