Shibaji's MATLAB presentation (from 2005)

advertisement
A Brief Introduction to MATLAB
Shibaji Shome and Rob MacLeod
CVRTI
University of Utah
What is MATLAB?
• MATrix LABoratory (The MathWorks,Inc)
• Easy access to matrix computation software
• Scientific computing and Visualization
package
• Arrays/matrices are at the heart of
MATLAB
• All data are stored as arrays
Ok, but what is MATLAB?
1) Concept of Workspace
2) In-Built functions - commands
3) M-scripts
4) User-defined functions
Workspace
•
•
•
•
Workspace initializes on launch
Front end to MATLAB
Access MATLAB functions
Manage variables
Workspace
•
•
Start MATLAB: Type “matlab” at system prompt / click application icon
On starting MATLAB:
* Matlab command window - your workspace
* Matlab command prompt - interact
Commands
• In built functions
• Manage environment, variables, commands,
functions
• Manage files, interact with the OS
• Perform computations, etc
M-Files or scripts
• Execute a batch of commands in a sequential
manner.
• Compartmentalize your commands, organize them
into a M-file.
• All variables and results are global ie can be
accessed from the workspace.
• Name your m-file (with a .m extension), execute
at command prompt by just typing the filename.
Functions
• Essentially user defined commands.
• Accept inputs from the workspace or another
function/command.
• Output to workspace or output becomes input to
another command/function.
• Encapsulation of variables.
• Only the outputs of a function are global.
• A function can call other functions within it, make
calls to itself recursively.
• Structures your program, makes it more flexible,
manageable and easy to debug.
Download