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]

urahonkyurahonky Cynical Old ManRegistered User regular
edited November 2010 in Help / Advice Forum
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!

urahonky on

Posts

  • RookRook Registered User regular
    edited November 2010
    I don't actually have matlab in front of me but it's something like:

    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,'-')

    Rook on
  • urahonkyurahonky Cynical Old Man Registered User regular
    edited November 2010
    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?

    urahonky on
  • DaenrisDaenris Registered User regular
    edited November 2010
    urahonky wrote: »
    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

    y = polyval(c,[-2,2]);
    plot([-2,2],y);

    Daenris on
  • urahonkyurahonky Cynical Old Man Registered User regular
    edited November 2010
    You guys are the best. Thank you, it worked perfectly!

    e: Does this work for a quadratic function? Or is there something like "quadval"?

    urahonky on
  • inlemurinlemur Registered User regular
    edited November 2010
    urahonky wrote: »
    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"

    inlemur on
    XBL - remura
  • urahonkyurahonky Cynical Old Man Registered User regular
    edited November 2010
    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!

    urahonky on
  • inlemurinlemur Registered User regular
    edited November 2010
    urahonky wrote: »
    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.

    inlemur on
    XBL - remura
  • urahonkyurahonky Cynical Old Man Registered User regular
    edited November 2010
    inlemur wrote: »
    urahonky wrote: »
    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....

    thanks :)

    urahonky on
Sign In or Register to comment.