03-Arrays-and-Data-in-MATLAB-4UP

03-Arrays-and-Data-in-MATLAB-4UP - char &...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: char & logical data Numeric data Arrays Arrays and Data in M ATLAB Dhavide Aruliah UOIT MATH 2070U c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 1 / 23 char & logical data Numeric data Arrays Arrays and Data in M ATLAB 1 char /string and logical /boolean data 2 Numeric data 3 Arrays c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 2 / 23 char & logical data Numeric data Arrays Strings and characters Variables of type char are letters, digits, spaces, symbols A string is an array of char Strings are enclosed by single quotes To include single quote ( ) in a string, type it twice Stings can be concatenated using brackets [ ] Strings can be indexed using parantheses ( ) >> command = Say Open sesame! next time. >> str1 = My name is ; >> str2 = input(Please enter your name: , s); >> sentence = [ str1, str2 ] % The comma is optional c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 4 / 23 char & logical data Numeric data Arrays Useful string utilities input receives input from user num2str converts numeric variable to string int2str converts integer variable to string disp displays strings to MATLAB session (also works for numbers/arrays directly) fprintf formatted output to files sprintf formatted output to strings strcmp comparison of strings format controls default behaviour of screen output c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 5 / 23 char & logical data Numeric data Arrays Logical operators Logical or boolean data: true (1) or false (0) Logical operators and truth tables Syntax Meaning and(a,b) a&b AND or(a,b) a|b OR not(a) ~a NOT xor(a,b) XOR and 1 1 1 or 1 1 1 1 1 not 1 1 xor 1 1 1 1 c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 6 / 23 char & logical data Numeric data Arrays Relational operators: > < >= <= == ~= Comparison of quantities important in numerical programming e.g., to compute sin- 1 ( 2 x 3- 4 ) , want | 2 x 3- 4 | 1 Syntax Meaning > (strictly) greater than < (strictly) less than >= greater than or equal to <= less than or equal to == equal to ~= not equal to Relational operators compare two numeric quantities Assignment operator = distinct from comparison == (More on logical variables when looking at control flow) c D. Aruliah (UOIT) Arrays and Data in MATLAB MATH 2070U 7 / 23 char & logical data Numeric data Arrays Real numbers in M...
View Full Document

This note was uploaded on 02/23/2010 for the course MATH 2070 taught by Professor Aruliahdhavidhe during the Spring '10 term at UOIT.

Page1 / 5

03-Arrays-and-Data-in-MATLAB-4UP - char &...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online