MATLAB For Dummies
Book image
Explore Book Buy On Amazon

You can create images using MATLAB. All you need is a mathematical model that describes the points used to describe the image shape. For example, to draw a square, you simply provide the x- and y-axis coordinate for each corner. You can see a number of these shapes demonstrated at The following steps help you create an image of your own.

  1. Type XSource = [1, 1, 5, 5]; and press Enter.

  2. Type YSource = [1, 5, 5, 1]; and press Enter.

    The XSource and YSource variables contain coordinates to draw a square. The lower-left corner is at 1,1; the upper-left corner is at 1,5; the upper-right corner is at 5,5; and the lower-right corner is at 5,1.

  3. Type fill(XSource, YSource, ‘b’); and press Enter.

    MATLAB creates the image, but the image consumes the entire drawing area. Notice that the image is filled with blue. You can choose any color you like using the options below. To see the image set apart from the plot area, you need to change the x and y limits.

  4. Type set(gca, ‘XLim’, [0, 6]); and press Enter.

  5. Type set(gca, ‘YLim’, [0, 6]); and press Enter.

    The image is now clear and in the center of the plot.


Selecting a color for your plot is important. This list contains the most common colors — those you can specify using a color letter or descriptive name. However, you can specify partial RGB values. For example, an RGB value of [.5, .25, 0] provides a nice brown. Each entry for red, green, and blue must have a value between 0 and 1.

RGB Value Color Letter Description
[1 1 0] y yellow
[1 0 1] m magenta
[0 1 1] c cyan
[1 0 0] r red
[0 1 0] g green
[0 0 1] b blue
[1 1 1] w white
[0 0 0] k black

About This Article

This article is from the book:

About the book authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: