I have the following two lines:
y = m1*x + c1 ;
y= m2*x +c2 ;
Now I want to draw those lines in an image in MATLAB?
I have the following two lines:
y = m1*x + c1 ;
y= m2*x +c2 ;
Now I want to draw those lines in an image in MATLAB?
This is a really basic question, and I am sure you should be able to look at Matlab help manual to solve. You want to first create a vector of discrete number of samples, and then plug the vector into your equations to generate the vector y, and then plot.
Something like:
x=1:0.01:100; %//Adjust accordingly for higher/lower resolution
y1=m1.*x+c1 %//Note the . product, since you are dealing with a vector x
y2=m2.*x+c2 %//Use the same x here, since you want both lines on the same graph.
figure
plot(x,y1,'r') %//plot y1 in red
hold on %//Allows to plot in same figure
plot(x,y2,'b') %//plot y2 in blue
I presume m1
, m2
, c1
and c2
are constants. You can use the plot
command to create plots.
m1=1; % Set them to some value so the code works
m2=2;
c1=1;
c2=2;
x = 1:0.1:10; % Define a range of x values to plot over
y1 = m1*x + c1 ;
y2= m2*x +c2 ;
figure; % Open figure
hold on
plot(x,y1,'r') % Make the actual plot.
plot(x,y2,'b')