{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MATLAB_tutorial

MATLAB_tutorial - An introductory tutorial on MATLAB in...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
An introductory tutorial on MATLAB in Image Processing ECE 178 (1-2pm Discussion batch, TA: Srivatsan Pallavaram) I. GETTING STARTED MATLAB is a data-analysis and visualization tool widely used by electrical engineers and stands for “Mathematics Laboratory.” The most important difference between MATLAB and C (or C++) is that functions in MATLAB are specifically written with a focus on large array- based operations in mind. Image processing is heavy on the memory usage as well as the run- time of programs. You would need the Image Processing toolbox installed in your MATLAB to work with the commands that are listed later in this worksheet. You can check if the Image Processing toolbox is installed using the ver command. Using “help images” one can see all the commands that are supported in this toolbox. If you find the help document scrolling past very fast you can switch the ‘more’ command using >> more on or for a more formal help use >> doc ‘command’ A MATLAB function is a keyword that accepts various parameters, and produces output of some sort. At times in this course, we may need to write our own functions (and this is very easy as you will see). A command is a particular usage of a function. Variables are elements used to store values. If you are using a windowed version of MATLAB, you may find a Workspace item in the View menu. This lists all your currently defined variables, their data types, sizes etc. Exercise 1: Explore the whos and who commands that are used to list the variables used in the workspace. At this point, I would like to stress that learning/ understanding MATLAB is impossible by just reading this handout. The exercises in this handout are motivated primarily by this reason. Using standard MATLAB routines “efficiently” Could mean the difference between a program that runs for a day and one that runs in an hour. Use of for loops is known to increase the run- time by a significant amount. Exercise 2: This exercise describes how ‘slow’ the for command can be. We can measure the time that elapses between the executions of a command using the tic toc timer of MATLAB. tic starts a stopwatch timer and toc stops it and prints out the elapsed time in seconds. Execute the following code and compare the elapsed time differences between the two. >> tic; for i = 1:10ˆ6, sin(i);end; toc; >> tic; i=1:10ˆ6; sin(i); toc; Understand how the for loop can slow down the process by quite a bit. II. BASIC MATRIX OPERATIONS IN MATLAB The standard data type of MATLAB operations is the matrix. Images, of course, are matrices whose elements are the gray values (or possibly the RGB values) of its pixels. I am assuming that most of you are aware of the basics of MATLAB. More information on these commands can be obtained using the help and lookfor commands. A standard 2 × 3 matrix is defined as >> A = [a11 a12 a13; a21 a22 a23;]; Matrix elements can be obtained using the standard row, column indexing scheme >> a(2,3) The reshape function produces a matrix with elements taken column by column from the given matrix. MATLAB also allows matrix
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern