How to Use Matlab to Generate Figures

MATLAB is a useful software program for performing literally thousands of different mathematical calculations, from arithmetic to calculus and everything in between. It’s also capable of collecting and storing data then plotting the results in a graph, or what MATLAB calls a figure. MATLAB can generate figures in two dimensions as well as in three dimensions. The basic 2-D plotting function is “plot” and it will draw you a line graph. The usual 3-D plotting function is “surf” and it will generate a 3-D, contoured, color-coded surface plot.

Instructions

  1. Basic 2-D Figure

    • 1

      Generate a list of x-axis values for the figure. For example, type this code at MATLAB’s command prompt:

      X = -10:1:10;

      Hit Enter. MATLAB will create an array that runs from -10 to 10 in steps of one and store it in a variable “X”.

    • 2

      Generate y-axis values for each x-axis value. For example, type this code:

      Y = X.^2;

      Hit Enter. MATLAB creates an array “Y” which stores the square of each values in “X.”

    • 3

      Generate the figure with this command:

      plot(X,Y)

      Hit Enter. MATLAB plots the graph of y = x^2 from -10 to 10.

    Basic 3-D Figure

    • 4

      Provide or generate a list of x-axis values for the figure. For example, type this code at MATLAB’s command prompt:

      X = rand(10,10)

      Hit Enter. MATLAB will create a 10-row by 10-column matrix of random numbers and store them as variable “X."

    • 5

      Provide or generate a list of x-axis values for the figure. For example, type this code at MATLAB’s command prompt:

      Y = rand(10,10)

      Hit Enter. MATLAB will create another 10-row by 10-column matrix of other random numbers and store them as variable “Y."

    • 6

      Establish the relationship between X, Y and Z with code like this:

      Z = X^.2 +2*Y.^2;

      Hit Enter. MATLAB creates a 10-row by 10-column matrix “Z” and stores in it values according to the equation above.

    • 7

      Generate the figure with this command:

      surf(X,Y, Z)

      Hit Enter. MATLAB opens a figure window and plots the data.

Related Searches:

References

Resources

Comments

Related Ads

Featured