Home

How to Create Images in MATLAB

|
Updated:  
2016-03-26 08:21:41
|
MATLAB For Dummies
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 MathWorks.com. The following steps help you create an image of your own.

image0.jpg
  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.

    image1.jpg

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 author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.