The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
Very, very simple MATLAB question (drawing a line) [SOLVED]
I know this is going to be dreadfully easy but I'm not sure how to do it. Basically I want to draw a continuous line on a plot that I have already drawn. I know the m, and the b. How do I draw this line? The values are:
c = [1.0018,2.1111]
Just not sure how I use this to draw a line... Any answers? Thanks!
So if I've got a dataset with x's and y's... I just use the beginning and ending values as the x and y's in that?
Assuming you are drawing a straight line (and since you mention you have the slope and intercept, I assume you are) then you just need 2 x values for the line (no y values, they will be calculated based on the coefficients you provide).
Just figure out where you want the lowest and highest x-value to be to make a good looking graph, and put those into the polyval function along with your c variable containing slope and intercept.
For example if you have c = [1.0018,2.1111], and you want to plot it along values of x from -2 to 2, you would do
You guys are the best. Thank you, it worked perfectly!
e: Does this work for a quadratic function? Or is there something like "quadval"?
Polyval works for any polynomial. You give it a vector P, and based on the number of values in P it will interpret it as the corresponding polynomial. That is, if P has 3 values, they are read as [A B C] in Ax^2+Bx+C.
Also MATLAB's built in help is outstanding. Try "help polyval"
Yeah I figured it out. I think their website is better than their help, since it has some examples. I don't think their help function gives those!
Actually, it does. And the command window help generally links to the full help files, with further details and examples. I really can't think of a program with better built-in help than MATLAB.
Yeah I figured it out. I think their website is better than their help, since it has some examples. I don't think their help function gives those!
Actually, it does. And the command window help generally links to the full help files, with further details and examples. I really can't think of a program with better built-in help than MATLAB.
Wow yeah I'm stupid. I don't know why I thought it didn't have them....
Posts
y = polyval(c,x)
where x is a vector containing the start and end points of your line. then you can just plot(x,y,'-')
Assuming you are drawing a straight line (and since you mention you have the slope and intercept, I assume you are) then you just need 2 x values for the line (no y values, they will be calculated based on the coefficients you provide).
Just figure out where you want the lowest and highest x-value to be to make a good looking graph, and put those into the polyval function along with your c variable containing slope and intercept.
For example if you have c = [1.0018,2.1111], and you want to plot it along values of x from -2 to 2, you would do
y = polyval(c,[-2,2]);
plot([-2,2],y);
e: Does this work for a quadratic function? Or is there something like "quadval"?
Polyval works for any polynomial. You give it a vector P, and based on the number of values in P it will interpret it as the corresponding polynomial. That is, if P has 3 values, they are read as [A B C] in Ax^2+Bx+C.
Also MATLAB's built in help is outstanding. Try "help polyval"
Actually, it does. And the command window help generally links to the full help files, with further details and examples. I really can't think of a program with better built-in help than MATLAB.
Wow yeah I'm stupid. I don't know why I thought it didn't have them....
thanks