Society & Culture & Entertainment Draw & Paint & Comics & Animation

How to Draw a Line in MATLAB

    • 1). Define a set of x-values. For example, type the following at MATLAB's command prompt and hit Enter:

      x = 0:1:10;

      MATLAB will create a list "x" of 11 numbers, ranging from zero to 10 in steps of one.

    • 2). Define a relation between the x-values and the y-values. For example, type the following at MATLAB's command prompt and hit Enter:

      y = 2*x;

      MATLAB will create a list "y" of 11 numbers, each corresponding to the x-value in the same position in the "x" list and deriving its value from the aforementioned formula.

    • 3). Draw or "plot" the line in MATLAB with the following command:

      plot(x,y)

      MATLAB will pop-up a window with a graph depicting the line you defined with the x-values and y-values in the previous steps.

Leave a reply