Lecture-28(matlab)

# Lecture-28(matlab) - • Function names that are available...

This preview shows pages 1–9. Sign up to view the full content.

Programming Elements of Matlab (Cont’d)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Logical Operators Logical OR (|) Logical negation (~) These operators act on an element-by- element basis of an array A B ~A A|B 0 0 1 0 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1
Logical Operators Remember that MATLAB treats any non-zero number as true and treats 0 as false If the variable is an array, then: AND operator >> A=[1,0,5] A = 1 0 5 >> ~A ans = 0 1 0 Not of each element in the array ans = 1 >> ~5 ans = 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Logical Operators >> B = [4,0,5] B = 4 0 5 >> A A = 1 0 5 ans = 1 0 1 ans = 0 0 0 B = 4 0 5 >> A A = 1 0 5 >> A | B ans = 1 0 1 >> A|~B ans = 1 1 1
Some examples of order of precedence Example 1 >> 18 > 13 < -1 ans = 0 Example 2 >> 3*5^2 ans = 75 Example 3 >> 3:6-5:4+1 ans = 3 4 5 Since the relational operators are all of same level of precedence, operation proceeds from left to right Exponentiation has precedence over multiplication Since addition and subtraction take precedence

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Variable/Function Names Reserved words: Some words such as break are internal MATLAB commands and cannot be used as variable name

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Function names that are available in MATLAB can be overloaded and assigned as variable names >> sin(6) ans =-0.2794 >> sin = 6 sin = 6 Built in function sin Overloaded and assigned as a variable name Variable/Function Names • Have to start with a alphabet (not number, not any other character) • Can be upto 31 characters in length • Remember that names of built in functions are case sensitive A123_data – acceptable 1A_data - unacceptable Scripts • An M-file is a script that contains a series of MATLAB commands. The M-file can be created using any text editor e.g. Notepad • The lines of commands in a script file are executed one line at a time. • Any value for a variable typed in the script supersedes any value that you had specified earlier in the command window Variables specified in the command window and in the script access the same memory space Script Example...
View Full Document

## This note was uploaded on 04/27/2008 for the course PGE 310f taught by Professor Srinivasan during the Spring '08 term at University of Texas.

### Page1 / 9

Lecture-28(matlab) - • Function names that are available...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online