Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot y=mx+b in Matlab?

Tags:

graph

plot

matlab

I was wondering if it is possible to plot a line of the form y = mx+b in Matlab? I used polyfit to get a 1x2 array that contains the slope and intercept.

Here is what I have so far:

lineFit = polyfit(tauBin, a5array, 1);
plot((lineFit(1)*x + lineFit(2)))

How can I plot this?

like image 640
Alex Nichols Avatar asked Dec 01 '22 08:12

Alex Nichols


1 Answers

There are two way that immediately come to mind. The first is with FPLOT:

>> m = 2; b = 1;
>> fplot(@(x)m*x+b, [0 10]);

The second is to calculate the y values directly in the call to the PLOT command:

>> m = 2; b = 1; x = 1:10;
>> plot(x, m*x+b);
like image 91
b3. Avatar answered Dec 02 '22 21:12

b3.