07-11-2012, 03:35 PM
An Introduction to Matlab
AnIntrtoMatlb.pdf (Size: 418.02 KB / Downloads: 81)
History of Matlab
• Developed by Cleve Moler in the late 1970s
• Designed to give easy access to EISPACK and LINPACK
• Rewritten in C in 1983; The Mathworks formed in 1984
• Always recognized as one of the leading programs for linear
algebra
• Very popular among engineers and image analysts, among
others
• Version 5, released in the late 1990s, added many new features
Function vs. Command format
Matlab commands can be called as functions (with parentheses and
comma-separated argument lists) or commands (separate tokens
separated by spaces). The primary difference is that the function
form uses the values of its arguments, while the command form
treats its arguments as literal strings. Additionally, only the
function form allows objects to be returned.
For example, to use the load command to load a saved matlab
data file called data.mat, you could use command syntax:
Data Entry: Overview
1. Entering a small data set – Values can be entered, separated by
spaces, and surrounded by square brackets ([]). To separate
rows, use a semi-colon (, or enter each row on a separate line.
2. The import wizard (File!Import Data in the console) guides
you through the data entry process.
3. The load command can be used to read saved matlab files, as
well as numeric data stored in ASCII files.
4. The dlmread and csvread commands can read data delimited
by a character other than a space.
5. The fopen function, in conjunction with the textscan
function, can flexibly read character and/or numeric data.
Some Basic Matrix Functions
• zeros - create a matrix of all zeroes
• ones - create a matrix of all ones
• diag - create diagonal matrix or extract diagonal elements
• reshape - change dimensions of matrix or vector
• rand - create matrix of uniform random numbers
• cat - concatenate matrices
• vertcat - concatenate matrices by rows
• blkdiag - construct block diagonal matrix
• eye - create identity matrix
Matrix and Vector Indexing (cont’d)
The sub2ind function can convert multiple indexes to single
indexes, and is useful to extract scattered elements from a matrix.
The first argument to sub2ind is a vector containing the size of the
matrix – the remaining arguments are interpreted as indices: