How to Graph Using MATLAB

How to Graph Using MATLAB thumbnail
Formatting options let you determine how MATLAB displays your graph.

MATLAB graphing starts in a new Command Window and ends with a visual display of the graph on your computer screen. The commands, or statements, you write work together to create a computer program that tells MATLAB to create a graph and display it in the manner you've selected. Start with a basic equation and an idea of how you want to display the information. Although comments within the code are optional, consider using them if your graph is complex or to explain the logic behind your commands.

Instructions

    • 1

      Write statements that identify plot points for the vertical "x" and horizontal "y" axes of your graph. Statements for a graph that plots average income according to age groups can appear as follows:

      x = [20, 30, 40, 50, 60, 70]
      y = [28.5, 30, 36.2, 41, 48, 42]
      plot(x, y)

    • 2

      Add identifying labels for the axes and include a title for your graph:

      x label = (‘Age Group’)
      y label = (‘Average Income (in thousands)’)
      title = (‘Average Income by Age Group’)

    • 3

      Format your graph to mark and connect the plot points. This is an optional statement; if you do not include it, MATLAB displays your graph using a black square to identify plot points and does not include a connecting line. A statement that displays plot points using an unfilled circle and connects plot points with a solid blue line appears as follows:

      plot(x, y, ‘g:-:o’)

    • 4

      Add optional grid lines to make your graph easier to read:

      grid on

    • 5

      Save your work and view the results on your screen.

Tips & Warnings

  • Identify comment lines by starting the line with a percent sign.

  • Write this block of code using any amount of whitespace you feel is necessary. MATLAB ignores whitespace, so whether you type statements in a single block or separate each section with a blank line, MATLAB reads your instructions the same way.

Related Searches:

References

Resources

  • Photo Credit Hemera Technologies/AbleStock.com/Getty Images

Comments

Related Ads

Featured