04 Arrays and Matrix Multiplication

# 04 Arrays and - 4 Arrays and Matrix Multiplication Arrays A collection of numbers a1 a2 an can be defined in MATLAB as an array An array is a type

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

4 – Arrays -1 4 - Arrays and Matrix Multiplication Arrays A collection of numbers, a 1 , a 2 ,... a n , can be defined in MATLAB as an array. An array is a type of data structure which is intrinsic to MATLAB. MATLAB is like any other programming language in that a single variable can reference an entire array. However, MATLAB does this more conveniently than most other languages because assigning the array elements (i.e., values) to the variable is especially straightforward. Square brackets are required for specifying arrays. Each element can be separated by commas and/or spaces. For example, we can assign all elements to an array named A with the following syntax >> A = [1, 2, 3, 4, 5]; or > >A=[ 12345 ] ; Suppose you typed >> A = [10, 3, -5, 20]; and then >> A(2) The output would be: ans = 3 You can access any element in an array using that element’s subscript or index number. Indices go inside round parentheses. (Parentheses are also used to specify the arguments of a function.

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.

## This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

### Page1 / 5

04 Arrays and - 4 Arrays and Matrix Multiplication Arrays A collection of numbers a1 a2 an can be defined in MATLAB as an array An array is a type

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

View Full Document
Ask a homework question - tutors are online