-2

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?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Robiul Islam
  • 95
  • 1
  • 2
  • 9

2 Answers2

5

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
GameOfThrows
  • 4,510
  • 2
  • 27
  • 44
  • I don't need to plot figure. I need to draw line to a image which is 2D binary matrix. line represent by 1 and other is 0. – Robiul Islam Aug 27 '15 at 17:54
1

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')
Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • I don't need to plot figure. I need to draw line to a image – Robiul Islam Aug 27 '15 at 11:19
  • This actually draws your lines, in an image. If you want to draw them onto an existing non-MATLAB file, that's a different question. (Although still easily done). – Adriaan Aug 27 '15 at 11:21