l2-1-1

2
 Create Numeric Arrays Create Numeric Arrays This example shows how to crea te a numer ic variable. In the MATLAB computing environment, all variables are arrays, and by default, numeric variables are of type  double (that is, double-precision values). For example, create a scalar value.  A = 100; Because scalar values are single element, 1-by-1 arrays, whos A returns Name Size Bytes Class Attributes  A 1x1 8 double To create a  matrix  (a two-dimensional, rectangular array of numbers), you can use the  [] operator. B = [12, 62, 93, -8, 22; 16 , 2, 87, 43, 91; -4, 17, -7 2, 95, 6] When using this operator, separate columns with a comma or space, and separate rows with a semi colo n. All rows must have the same number of elements. In this example, B is a 3-by-5 matrix (that is,  B has three rows and five columns). B = 12 62 93 -8 22 16 2 87 43 91 -4 17 -72 95 6  A matrix with only one row or column (that is, a 1-by-n or  n-by-1 array) is a  vector, such as C = [1, 2, 3] or D = [10; 20; 30] 1-3

Upload: ahmed-a-hwaidi

Post on 04-Nov-2015

216 views

Category:

Documents


0 download

DESCRIPTION

MATLAB Matrices

TRANSCRIPT

  • Create Numeric Arrays

    Create Numeric ArraysThis example shows how to create a numeric variable. In the MATLABcomputing environment, all variables are arrays, and by default, numericvariables are of type double (that is, double-precision values). For example,create a scalar value.

    A = 100;

    Because scalar values are single element, 1-by-1 arrays,

    whos A

    returns

    Name Size Bytes Class Attributes

    A 1x1 8 double

    To create a matrix (a two-dimensional, rectangular array of numbers), youcan use the [] operator.

    B = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6]

    When using this operator, separate columns with a comma or space, andseparate rows with a semicolon. All rows must have the same number ofelements. In this example, B is a 3-by-5 matrix (that is, B has three rowsand five columns).

    B =12 62 93 -8 2216 2 87 43 91-4 17 -72 95 6

    A matrix with only one row or column (that is, a 1-by-n or n-by-1 array) isa vector, such as

    C = [1, 2, 3]

    or

    D = [10; 20; 30]

    1-3

    tocLanguageSyntax BasicsCreate VariablesCreate Numeric ArraysStore Text in Character StringsEnter Multiple Statements on One LineContinue Long Statements on Multiple LinesCall FunctionsIgnore Function OutputsVariable NamesValid NamesConflicts with Function Names

    Case and Space SensitivityCommand vs. Function SyntaxCommand and Function SyntaxesAvoid Common Syntax MistakesPassing Variable Names

    How MATLAB Recognizes Command Syntax

    Program ComponentsOperatorsArithmetic OperatorsArithmetic Operators and Arrays

    Relational OperatorsRelational Operators and ArraysRelational Operators and Empty Arrays

    Logical OperatorsElement-Wise Operators and FunctionsBit-Wise FunctionsShort-Circuit Operators

    Operator PrecedencePrecedence of AND and OR OperatorsOverriding Default Precedence

    Special ValuesConditional StatementsLoop Control StatementsDates and TimesRepresenting Dates and Times in MATLABDates and Dates with Time

    Date and Time FunctionsWorking with Date StringsCreating Date Strings In MATLABSpecifying the Fields of a Date StringCreating Multiple Date StringsTime Display in Date Strings

    Date String TablesSymbolic Identifiers for Individual FieldsNumeric Identifiers for Predefined Formats

    Working with Date VectorsCreating a Date VectorConverting from Date String to Date VectorConverting from Serial Date Number to Date VectorCreating Multiple Date VectorsMilliseconds in Serial Date NumbersExamples of Using Date Vectors

    Working with Serial Date NumbersConverting from Date String to Serial Date NumberConverting from Date Vector to Serial Date NumberCreating Multiple Serial Date NumbersUsing Serial Date Numbers For Elapsed TimeExamples of Using Serial Date Numbers

    Other ConsiderationsCarrying to the Next FieldSpecifying a Pivot YearDate Vectors vs. Vectors of Date Numbers

    Function Summary

    Regular ExpressionsOverviewCalling Regular Expression Functions from MATLABMATLAB Regular Expression FunctionsReturning the Desired InformationModifying Parameters of the Search (Modes)

    Parsing Strings with Regular ExpressionsStep 1 Identify Unique Patterns in the StringStep 2 Express Each Pattern as a Regular ExpressionStep 3 Call the Appropriate Search Function

    Other Benefits of Using Regular ExpressionsParsing or Replacing with Multiple Expressions and StringsReplacing Parts of a StringMatching with Tokens Taken from the StringMatching and Replacing Strings Dynamically

    Metacharacters and OperatorsCharacter Type OperatorsAny Character .Selected Characters [c1c2c3]Range of Characters [c1 - c2]Word and White-Space Characters \w, \sNumeric Digits \d

    Character RepresentationOctal and Hexadecimal \o, \x

    Grouping OperatorsGrouping and Capture (expr)Grouping Only (?:expr)Alternative Match expr1|expr2

    Nonmatching OperatorsIncluding Comments (?#expr)

    Positional OperatorsStart and End of String Match ^expr, expr$Start and End of Word Match \Exact Word Match \

    Lookaround OperatorsUsing the Lookahead Operator expr(?=test)Using the Negative Lookahead Operator expr(?!test)Using the Lookbehind Operator (?