Lecture-28(matlab)

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

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

View Full Document Right Arrow Icon
Programming Elements of Matlab (Cont’d)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Variable/Function Names Reserved words: Some words such as break are internal MATLAB commands and cannot be used as variable name
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
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 Right Arrow Icon
Ask a homework question - tutors are online