0% found this document useful (0 votes)
3 views

Module 1.Pptx

The document provides an introduction to MATLAB programming, highlighting its features, capabilities, and user interface components. It covers basic arithmetic operations, array manipulation, and the various types of files used in MATLAB, including M-files and Mat-files. Additionally, it compares MATLAB with Scilab and discusses the platform independence of MATLAB.

Uploaded by

bhagya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 1.Pptx

The document provides an introduction to MATLAB programming, highlighting its features, capabilities, and user interface components. It covers basic arithmetic operations, array manipulation, and the various types of files used in MATLAB, including M-files and Mat-files. Additionally, it compares MATLAB with Scilab and discusses the platform independence of MATLAB.

Uploaded by

bhagya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

National Education Society (R.

)
Jawaharlal Nehru New College of Engineering, Shivamogga
(Approved by AICTE, New Delhi, Certified by UGC 2f & 12B, Accredited by NAAC –‘B’,
Recognized by Govt. of Karnataka and Affiliated to VTU, Belagavi)

MATLAB PROGRAMMING
Module 1: Introduction

Faculty: Dr. Ashwini S R


Associate Professor
E & T E Dept. JNNCE
Module 1

Introduction: Basics of MATLAB, Simple


arithmetic calculations, Creating and
working with arrays and numbers.
What is MATLAB?
• MATrix LABoratory
• Software package for high-performance
numerical computation and visualization
• Interactive environment
• Has built-in functions for technical
computation, graphics & animation.
Main features and capabilities of MATLAB
MATLAB

MATLAB
programming
language

User written functions /


Built-in functions

COMPUTATIONS
EXTERNAL
GRAPHICS •Linear algebra
INTERFACE
•2-D graphics •Data analysis
(MEX-FILES)
•3-D graphics •Signal processing
•Interface with C,
•Color & lighting •Polynomials &
Java & Fortran
•Animation interpolation
Programs
•Audio & video •Quadrature
TOOL BOXES •Solution of ODEs
(Collections of Specialized Functions)
•Signal processing
•Statistics
•Control systems
•System Identifications

•Neural Network
•Communication
•Image processing
•Optimization
•M-analysis & Synthesis
•Finance
light("Style","local","Position",[-10 -10 0]);
FEATURES of MATLAB
It is designed for numerical as well as symbolic
computing.

It's a high-level language used mainly for


engineering and scientific computing.

It works within a Desktop environment


providing full features for iterative exploration,
design, and problem-solving.

Creation of custom plots for visualizing data and


tools, with the help of built-in Graphics.
Specific applications are designed to work with
any particular type of problems, such as data
classification, control system design and tuning,
signal analysis.
Provides several add-on toolboxes to build a
wide range of engineering, scientific, and
custom user interface applications.
Provide interfaces to work with other
programming languages such as C, C++, Java,
.NET, Python, SQL, Hadoop.
Does MATLAB Do Symbolic Calculations

•User
friendly,
Ease of easy for
beginne
Use rs to
learn
and use
•Fast
Performa calculati
ons like
nce C or
Fortran
•World
wide
Widespr use in
academi
ead use a and
industri
es
•Support
Compati s
bility multiple
file
formats
SCILAB
•Scilab is open source powerful computing
environment for scientific and engineering
applications.
•Scilab is one of major alternative for Matlab.
•Matrix is main data type.
•It includes many mathematical
functions-e.g. maths & statistics, 2D and 3D
visualization, signal Processing , Image
Processing, control system and so on…
Matlab Vs scilab
Basics of MATLAB
MATLAB windows

1. MATLAB Desktop

Command window
Current Directory pane
SUB-WINDOWS
(File) Details pane

Workspace pane

Command History pane

2. Figure window

3. Editor window
1. Command window
1. Command window
• This is the main window. It is characterized by the MATLAB command prompt (>> ).
• When you launch the application program, MATLAB puts you in this window.
• All commands, including those for running user-written programs, are typed in this
window at the MATLAB prompt.
• In MATLAB, this window is a part of the MATLAB window that contains other smaller
windows or panes.
3. (File) Details Pane
• Just below the Current Directory pane is
the Details pane that shows the details of
a file you select in the current directory
pane.
• These details are normally limited to
listing of variables from a MAT-file,
showing titles of M- files, and listing
heading of cells if present in M-files.
2. Current Directory Pane
• This pane is located on the left of the Command Window in the default
MATLAB desktop layout.
• This is where all your files from the current directory are listed. You
can do file navigation here.
• This little window and the current directory pane are interlinked;
changing the directory in one is automatically reflected in the other
4. Workspace Pane
• This sub-window lists all variables that you have generated so far and
shows their type and size.
• You can do various things with these variables, such as plotting, by
clicking on a variable and then using the right button on the mouse to
select your options.
5. Command History Pane
• All commands typed on the MATLAB prompt in the command window get
recorded
• You can select a command from this window with the mouse and execute it in
the command window by double-clicking on it.
• You can also select a set of commands from this window and create an M-file
with the right click of the mouse (and selecting the appropriate option from
the menu) .
Figure window
• The output of all graphics command typed in the command window
are flushed to the graphics or figure window, a separate gray window
with (default) white background color.
• The user can create as many figure windows as the system memory
will allow.
Editor window
• This is where you write, edit , create & save your programs in files called M-files.
• You can use any text editor to carry out these tasks.
• You can use your own editor by typing the
standard file-editing command that you normally
use on your system.
• From within MATLAB, the command is typed at the
MATLAB prompt following the exclamation
character (!). The exclamation character prompts
MATLAB to return the control temporarily to the
local operating system, which executes the
command following the character.
• After the editing is completed, the control is
returned to MATLAB.
On-line help
• On-line documentation: MATLAB provides on-line help for all its built in
functions and programming language constructs. The commands look for,
help, helpwin, and helpdesk provide on-line help.
• Demo: MATLAB has a demonstration program that shows many of its
features. Type demo at the MATLAB prompt to invoke the demonstration
program & follow the instructions on the screen.
Input-output
• MATLAB supports interactive computation
• Taking the input from the screen
• Flushing the output to the screen.
• It can read input files and write output files.
The following features hold for all forms of input-output:

• Data type: The fundamental data type in MATLAB is an array.


• It has several distinct data objects-integers, doubles (real numbers), matrices,
character strings, structures and cells.
• In most cases, you never have to worry about the data type or the data object
declarations.
• For example, there is no need to declare variables as real or complex. When a
real number is entered as the value of a variable, MATLAB automatically sets
the variable to be real (double) .

• Dimensioning: Dimensioning is automatic in MATLAB .


• No dimension statements are required for vectors or arrays.
• You can find the dimensions of an existing matrix or a vector with the size and
length (for vectors only) commands.

• Case sensitivity: MATLAB is case-sensitive, it differentiates between lowercase


and uppercase letters.
• Thus a and A are different variables.
• Most MATLAB commands and built-in function calls are typed in lowercase
letters.
• Output display: The output of every command is displayed on the screen
unless MATLAB is directed otherwise.
• A semicolon at the end of a command suppresses the screen output,
except for graphics and on-line help commands.
• The following facilities are provided for controlling the screen output: -
• Paged output: To direct MATLAB to show one screen of output at a time,
type more on at the MATLAB prompt.
• Without it, MATLAB flushes the entire output at once, without regard to
the speed at which you read.
• Output format: Though computations inside MATLAB are performed using
double precision, the appearance of floating point numbers on the screen is
controlled by the output format in use.
• There are several different screen output formats. The following table
shows the printed value of 10π in seven different formats.
format short 31.4159
format short e 3.1416e+001
format long 31.41592653589793
format long e 3.141592653589793e+001 format
short g 31.416
format long g 31.4159265358979
format hex 403f6a7a2955385e
format rat 3550/113
format bank 31.42
Default format is short
• Command history: MATLAB saves previously typed commands in a
buffer.

• These commands can be recalled with the up-arrow key (↑). This
helps in editing previous commands.

• You can also recall a previous command by typing the first few
characters and then pressing the ↑ key.

• Alternatively, you can double-click on a command in the Command


History pane to execute it in the command window.
File types

MATLAB can read and write several types of files. Five different types of files for storing
data or programs that you are likely to use often:
• M-files are standard ASCII text files, with a .m extension to the filename.
• There are two types of these files: script files and junction files.
• Most programs you write in MATLAB are saved as M-files. All built-in functions in
MATLAB are M-files and reside on your computer in precompiled format.
• Some built-in functions are provided with source code in readable M-files so that
they can be copied and modified.
• Mat-files are binary datafiles, with a .mat extension to the filename.
• Mat-files are created by MATLAB when you save data with the save command.
• The data is written in a special format that only MATLAB can read.
• Mat-files can be loaded into MATLAB with the load command.
• Fig-files are binary figure files with .fig extension that can be opened again in
MATLAB as figures.
• Such files are created by saving a figure in this format using the Save or Save
As options from the File menu or using save as command in command window.
• A fig-file contains all the information required to recreate the figure. Such files
can be opened with the open filename .fig command.
• P-files are compiled M-files with a .p extension that can be executed in MATLAB
directly (without being parsed and compiled).
• These files are created with the pcode command.
• We can develop an application that other people can use but do not want to
give them source code (M- file), then give them corresponding p-code or p-file.
• Mex-files are MATLAB-callable Fortran, C, and Java programs, with a .mex
extension to the filename. Use of these files requires some experience with MATLAB
and a lot of patience.
Platform dependence
• MATLAB is its platform independence.
• It does not matter which computer you are on. Almost all
commands work the same way.
• The only commands that differ are the ones that necessarily
depend on the local operating system, such as editing (if you do
not use the built-in editor) and saving M-files.
• Programs written in the MATLAB language work exactly the same
way on all computers. The user interface (how you interact with
your computer) may vary a little from platform to platform.
Launching MATLAB
• If MATLAB is installed on your machine correctly then you can launch it
by following these directions:
• On PCs:
• Navigate and find the MATLAB folder
• Locate the MATLAB program
• Double-click on the program icon to launch MATLAB.
• If you have worked in MATLAB before and have an M-file or Mat-file
that was written by MATLAB, you can also double-click on the file to
launch MATLAB.
• On UNIX machines:
• Type MATLAB on the UNIX prompt and hit return or enter.
• If MATLAB is somewhere in your path, it will be launched.
• If it is not, ask your system administrator
Creating a directory and saving files
•MATLAB creates a default folder called MATLAB inside My
Documents (on PCs) where it saves your files if you do not
specify any other location.
•You can create a directory /folder anywhere, save your files,
and direct MATLAB to find those files.
•If you need to store the files somewhere else, you might
have to specify the path to the files using the path
command, or change the working directory of MATLAB to
the desired directory with a few navigational clicks in the
Current Directory pane.
Printing

• On PCs: To print the contents of current active window (command,


figure, or edit window), select Print... From File menu and click Print
in dialog box.
• You can also print the contents of figure window by typing print at
MATLAB prompt.
General commands you should remember
General commands you should remember
Simple arithmetic calculations

To learn how to log on, invoke MATLAB, do a few trivial calculations, quit
MATLAB, and log off.

+ addition
- subtraction
* multiplication
/ division
^ exponentiation
+, -, *, /, ^
sin, cos, log
quit
Simple arithmetic calculations
Creating and Working with Arrays of Numbers

• An array is a list of numbers or expressions arranged in


horizontal rows and vertical columns.
• When an array has only one row or column, it is called a
vector.
• An array with m rows and n columns is called a matrix of
size m x n.

You might also like