Arrays

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

MATLAB

ARRAYS IN PROGRAMMING
ARRAY DEFINITION

• An array is a collection or systematic arrangement


of objects of the same data type.

a1 a2 a3 . . . . . an

• Arrays are very important in programming


especially in MATLAB.

• MATLAB considers any variable is an array even if


that variable is a single number, it’s 1X1 array.
ARRAY EXAMPLE

• If you have 10 students in your class and you want


to sort their grades to calculate for example the
average grade, maximum and minimum grades.

• You can define 10 variables for each grade s1, s2,


s3, s4, . . . . s10. the calculate the Avg. Max & Min.

• What if you have 500 students !!


TYPES OF ARRAYS

• One dimensional array (Vector)

𝒂= 𝟏𝟑𝟒𝟓𝟔

𝟏
𝒂=𝟐
𝟎

• Two dimensional array (Matrix)

𝟏 𝟑 𝟒
𝒂=𝟎 𝟎 𝟗
𝟔 𝟑 −𝟏
• Multidimensional arrays
ARRAYS ELEMENTS

• Each element inside an array has an index.

• An index shows the order or the place of an


element inside the array

𝟓 𝟓 𝟔
𝒂= 𝟖 𝟒 𝟎
𝟖 𝟔 𝟎
SECTION OVERVIEW

• Creating Arrays

• Selecting different elements from arrays.

• Some functions that are used with arrays.

• Basic Operations on Arrays.

You might also like