You are on page 1of 12

Essentials of MATLAB® Programming, 3rd Edition Chapman

Chapter 1
Introduction to MATLAB

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly
accessible website, in whole or in part.
1
Essentials of MATLAB® Programming, 3rd Edition Chapman

Overview

 Introduction
 1.1 The Advantages of MATLAB
 1.2 Disadvantages of MATLAB
 1.3 The MATLAB Environment
 1.4 Using MATLAB as a Calculator
 1.5 Summary

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

2
Essentials of MATLAB® Programming, 3rd Edition Chapman

Introduction

 MATLAB is short for MATrix LABoratory

 MATLAB is a combination of:


 a procedural programming language
 an integrated development environment (IDE) + editor
and debugger
 an extremely rich set of built-in functions to perform many
types of technical calculations

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

3
Essentials of MATLAB® Programming, 3rd Edition Chapman

Introduction

 Normally MATLAB experts are hired by any scientist lab,


education institute, Research centre or working as a
student of PhD.

 MATLAB mainly popular to use for below activities:


 Data analyzation
 Algorithm development
 Create different models with varieties application.

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

4
Essentials of MATLAB® Programming, 3rd Edition Chapman

1.1 The Advantages of MATLAB

 Ease of Use – interpreted language, rapid prototyping


 Platform Independence – Windows, Linux, Unix, Macintosh
 Predefined Functions – extensive library, prepackaged
solutions, special-purpose toolboxes
 Device-Independent Plotting – display on any graphical output
device
 Graphical User Interface – design sophisticated programs to
be operated by any user
 MATLAB Compiler – speeds up interpreted language

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

5
Essentials of MATLAB® Programming, 3rd Edition Chapman

1.2 Disadvantages of MATLAB

 MATLAB has two principal disadvantages:


 Interpreted Language – executes more slowly than
compiled languages; slowness can be mitigated through
proper structure, minimizing performance of vectorized code,
use of JIT compiler
 Cost – full copy of MATLAB costs 5-10 times as much as a
conventional C or Fortran compiler; cost-effective for
businesses, not for individuals (student editions available)

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

6
Essentials of MATLAB® Programming, 3rd Edition Chapman

1.3 The MATLAB Environment


Workspace
Browser
shows variables
defined in
workspace
Current Folder
Browser
shows a list of MATLAB
the files in the Editor
current folder

Details MATLAB
Window Command
displays Window
properties of file
selected above
© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

7
Essentials of MATLAB® Programming, 3rd Edition Chapman

Getting Help in MATLAB

 There are three ways to get help in MATLAB

 The preferred method is to use the Help Browser

 There are also two command-line oriented ways to get help: the help and
lookfor commands

 The help command searches for an exact function name match, while the
lookfor command searches the quick summary information in each
function for a match

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

8
Essentials of MATLAB® Programming, 3rd Edition Chapman

A Few Important Commands

Function Description
demo run MATLAB’s built-in demonstrations
clc clear the Command Window
clf clear the contents of the current figure window
clear clear the variables in the workspace
control-c abort running program, returns a command
prompt
diary keep track of everything done in MATLAB session

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

9
Essentials of MATLAB® Programming, 3rd Edition Chapman

The MATLAB Search Path

 If a user enters a name at the MATLAB prompt, the MATLAB interpreter


attempts to find the name as follows:
1. It looks for the name as a variable. If it is a variable, MATLAB displays the
current contents of the variable
2. It checks to see if the name is an M-file in the current directory. If it is,
MATLAB executes that function or command
3. It checks to see if the name is an M-file in any directory in the search path. If
it is, MATLAB executes that function or command

 MATLAB includes the which command to help you find out just which version
of a file is being executed and where it is located

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

10
Essentials of MATLAB® Programming, 3rd Edition Chapman

1.4 Using MATLAB as a Calculator

 In its simplest form, MATLAB can be used as a calculator to


perform mathematical calculations

 Use the symbols +, -, *, /, and ^ for addition, subtraction,


multiplication, division, and exponentiation respectively

 The value in ans can be used in later calculations. But be careful!


Every time a new expression without an equal sign is evaluated,
the value saved in ans will be overwritten.

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

11
Essentials of MATLAB® Programming, 3rd Edition Chapman

1.5 Summary

 We learned about the MATLAB desktop (Command Window, Toolstrip,


Document Window, Workspace Browser, Current Folder, etc.)

 A MATLAB user can get help by either using the Help Browser or the
command-line help functions help and lookfor

 When a user types a command in the Command Window, MATLAB


searches for that command in the directories specified in the MATLAB
path and executes the first M-file in the path that matches the
command

© 2018 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

12

You might also like