Module 1.Pptx
Module 1.Pptx
)
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
MATLAB
programming
language
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.
•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
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:
• 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.
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
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