From Process Model Formulation and Solution: 3E4
Jump to navigation
Jump to search
|
|
Line 92: |
Line 92: |
|
| |
|
| ====Current Directory==== | | ====Current Directory==== |
| The current directory panel lists all of the files (MATLAB or other) that are located in the directory MATLAB is currently accessing. This directory may be changed via the drop down address bar at the top of the main program window. For a program to run properly, ALL CODES required must be in the same directory (for example, if you write a main script file that calls a separate function file, both files must be in the same directory). | | (2) The "current directory" panel lists all of the files (MATLAB or other) that are located in the directory MATLAB is currently accessing. This directory may be changed via the drop down address bar at the top of the main program window. For a program to run properly, ALL CODES required must be in the same directory (for example, if you write a main script file that calls a separate function file, both files must be in the same directory). |
|
| |
|
| ====Command History==== | | ====Command History==== |
| The command history | | (3) The command history records all commands entered in the command window (for possible future reference). |
| | |
| ====Workspace==== | | ====Workspace==== |
| | (4) The workspace lists all variables, matrices, and function handles currently being stored by MATLAB. The workspace also provides basic information on the values being stored, such as size, max, min, etc. Perhaps most useful is the ability to double click variables and matrices in the workspace to open up the '''Variable Editor''' window. The variable editor is essentially a spread sheet representation of your variables that allows for easy manipulation (especially useful for large matrices). |
|
| |
|
| ====Editor Window==== | | ====Editor Window==== |
| where you can write functions and scripts (to be discussed in detail later) | | (5) The editor window(s) does not immediately open when you launch MATLAB. The editor window is where you write scripts and function files that can be compiled and run in the command window (to be discussed in detail later). To open a new editor window you can either go to File>New>Blank M-File, hit ctrl+N, type "edit" at the command line, or hit the "New M-File" icon at the top left of the main screen (it looks like the little piece of paper with the explosion in the top left corner). To open a pre-existing M-File you need to switch the current directory to the location of the file (as mentioned above) and simply double click on the M-File name in the "current directory" sidebar. |
|
| |
|
| ====Plot Window==== | | ====Plot Window==== |
Revision as of 12:06, 10 September 2010
Introduction
MATLAB
MATLAB (MATrix LABoratory) is a high level computer language/ interactive software package developed and distributed by MathWorks™. Matlab was first developed in the 1970s by Cleve Molar. Cleve was later joined by John N. Little and Steve Bangert and the three went on to found MathWorks™. MATLAB excels at performing matrix operations and can handle large data sets sets (stored as matrices) very easily. MATLAB was originally designed as a user friendly interface for LINPACK and EISPACK and so was intended for linear algebra application. Since then MATLAB has greatly expanded it's core abilities to encompass a large array of graphic and numeric applications. These core abilities may in turn be expanded further through the addition of specialized "tool boxes".
|
|
|
Access / Installation
MATLAB
MATLAB is installed on all computers in the John Hodgins Engineering Student Technology Centre (JHE 233A / 234) as well as the Burke Science Building Labs (BSB 241 / 242 / 244 / 249). The most up to date release of MATLAB is version R2010b. The versions installed in JHE and BSB are ???? and ???? respectively. While there are some backward compatibility issues when it comes to older versions of MATLAB, for the level of code that will be encountered in this class students should not encounter issues with portability of code. MATLAB is proprietary software and so no free versions exist (legally...). A MATLAB/SIMULINK student package (version R2010A, good for Windows, Mac, and Linux) is available at the University Book Store for $112.95 (for those students who would like a copy of MATLAB on their laptop or home PC). The student versions comes with the following features:
- MATLAB version R2010a (Everything you need to get started)
- Simulink (Will be useful in your control classes)
- Control System Toolbox
- Signal Processing Toolbox
- Signal Processing Blockset
- Statistics Toolbox
- Optimization Toolbox
- Symbolic Math Toolbox
- Image Processing Toolbox
- Product Demos
I personally have a student copy on my home PC. It's a good buy if you have the extra cash.
Accessing MATLAB in JHE
MATLAB may be accessed in the JHE computer labs using the following steps:
- Open the start menu
- Go to
Accessing MATLAB in BSB
MATLAB may be accessed in the BSB computer labs using the following steps:
- Open the start menu
- Go to
|
|
|
Getting Started
MATLAB
- When you launch MATLAB the following window will open:
- Do not worry if MATLAB does not open exactly like this. You can easily modify what windows are visible through the Desktop drop down menu. You can select the windows you want either by toggling them individually (Region A) or by selecting a template (Region B). Selecting the default template should give you the window layout you saw above.
- The core MATLAB setup has 6 main sections of interest that you will become very familiar with by the end of this course:
Command Window
(1) The command window (or "command line") provides your main means of interacting with the MATLAB software. The command line allows you to enter simple codes that are processed immediately. All program outputs also appear in the command window. While it is technically possible to write an entire program at the command line, this is not recommended. For true programs, scripts and functions will be used.
Current Directory
(2) The "current directory" panel lists all of the files (MATLAB or other) that are located in the directory MATLAB is currently accessing. This directory may be changed via the drop down address bar at the top of the main program window. For a program to run properly, ALL CODES required must be in the same directory (for example, if you write a main script file that calls a separate function file, both files must be in the same directory).
Command History
(3) The command history records all commands entered in the command window (for possible future reference).
Workspace
(4) The workspace lists all variables, matrices, and function handles currently being stored by MATLAB. The workspace also provides basic information on the values being stored, such as size, max, min, etc. Perhaps most useful is the ability to double click variables and matrices in the workspace to open up the Variable Editor window. The variable editor is essentially a spread sheet representation of your variables that allows for easy manipulation (especially useful for large matrices).
Editor Window
(5) The editor window(s) does not immediately open when you launch MATLAB. The editor window is where you write scripts and function files that can be compiled and run in the command window (to be discussed in detail later). To open a new editor window you can either go to File>New>Blank M-File, hit ctrl+N, type "edit" at the command line, or hit the "New M-File" icon at the top left of the main screen (it looks like the little piece of paper with the explosion in the top left corner). To open a pre-existing M-File you need to switch the current directory to the location of the file (as mentioned above) and simply double click on the M-File name in the "current directory" sidebar.
Plot Window
Where plots are displayed
|
|
|
Introduction to the Command Line
MATLAB
- MATLAB IS CASE SENSITIVE!!! For example, A is not the same thing as a. This is very important when working with variable and function names.
Common Command Line Commands and Functions
doc function_name
Brings up information on any built-in MATLAB function
edit
Opens the text editor
clc
Clears the screen
clear
Clears the variables from the workspace (and from memory)
Built in Functions
Commonly used built in MATLAB functions (most of these are self-explanatory)
Built in Constants
Prede�ned constants include
fprintf() and disp()
To display output on the screen use disp() or for more organized display use fprintf()
Semicolon
Placing a semicolon at the end of a line of code will suppress any output produced by that line
Variables
Matrices
Matrix Operations
Dot and Colon Operator
Accessing Submatrices
Concatenation
|
|
|
Scripts and Functions
Code Structures
Plotting Data
Additional Resources