Download Presentation
## Lecture 4

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Lecture 4**MATLAB Windows Arithmetic Operators Maintenance Functions Basic Math Functions Help/Doc Scripts P: Drive Comments**Fundamental components of MATLAB**• MATLAB stands for Matrix Laboratory • MATLAB = a calculator + a lot more • A computing system that interprets one instruction at a time. Instructions MUST conform to a specific syntax and vocabulary. • A large library of modules that provide high-level capabilities for processing data. • A collection of toolboxes, some providing graphical capabilities. • A graphical user interface (GUI) to allow you to assemble your own professional looking software.**Starting MATLAB**• Opening MATLAB in LB172: computer should have a direct shortcut on the desktop • Any other LAB on campus, search: • If not, use Ernie (directions online) Double Click to bring up the MATLAB Interface**DONOT USE CITRIX IN THE LAB**• Why? …**“Workspace”**“The Command Window” “Current Directory” Shows the variables that have been created. “Your Calculator Screen” You can do exactly as on your calculator: add, subtract, divide, multiple, use parentheses to override the order of operations… Later on, you will realize you can do a LOT more in this frame. This frame shows the files (excel, text, MATLAB files) that can immediately be used. “Command History” It will show all the commands executed previously. None of these are helpful to write re-usable code.**1. Basic Data Manipulation**• Starting MATLAB leads to the prompt symbols>> in the command window • If you don’t see the prompt symbols, MATLAB is busy MATLAB is loading MATLAB is doing 1,000,000 calculations… MATLAB has crashed MATLAB is stuck**Overview: most Operators**• There are 3 primary groups of operators • One operator is very different in programming compared to math**MATLAB as a Calculator**• The MATLAB command window can be used as a boring old calculator. • Precedence is similar to most calculators with a few MATLAB specific things. Left to right based on these things: 8**MATLAB as a Calculator**• Mistake you’ll make at least once! • Power is before signage: -3^2 is different than (-3)^2 9**Demo MATLAB as a calculator in the command window (without**variables) • Any single line contains a command/statement/instruction (different words for the same concept) • The ans variable is the default location where MATLAB stores results.**Maintenance Functions**• clear • clc • close all • commandwindow**Basic Math Functions**• sin • cos • tan • sind • sqrt • abs • help vs. doc • help elfun**the “Editor”**• “Open a new script file"**A new window: the Editor**This is where you’ll create a “script file” Save these type of files (on your P:/ drive ) absolutely re-usable**A new window: the Editor**“Dock” this window to make it part of the regular windows below**How to write “code”…**2. Run your statements (or hit F5) 1. Type your statements, your code, your instructions,… here (Modify your statements, repeat cycle) 3. See your results here**P: Drive**• The P: drive is space provided by ERAU that you can access from any ERAU computer. • Getting files from your P: drive to your personal computer can be done through ERNIE/Citrix/Network File Access, but all the transferring must be done from within that program and it is sometimes grouchy.**Comments**• Comments are the most important part of your code. • Put the algorithm steps (7a) in comments before you start • Write the code that goes with the comments • Update the comments to make them more detailed where needed. • Someone else should be able to write your code based on your comments. • % <- Supported by all versions of MATLAB • %{ <- Must not have anything else on the line with open/close %} (Not supported in versions before 7/R14/2004)**Lessons learned**• New Vocabulary • Command window • Workspace • Current Folder/Current Directory • Command History • Command • Statements • Instructions • Prompt symbols • Script file