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

Introduction to MATLAB

MATLAB BASICS
PART 2
Initializing and Assigning Arrays

 temp_range = 0:0.01:50

 angles = (0.01:0.01:1.00)*pi

 Array1 = [1 2 3;4 5 6;7 8 9];

 Array2 = [1:10;11:20;21:30];

 Array3(2,3)= 3;
Initializing and Assigning Arrays

 Assignment using MATLAB built-in functions:


 a = zeros(3);

 b = zeros(2,3);

 c = ones(3);

 d = ones(2,3);

 I1 = eye(3);

 I2 = eye(5,3);
Initializing and Assigning Arrays

 Some useful MATLAB built-in functions:


 size(Array)
 Returns the values of the dimension of Array: row then column
 Examples
 size(Array1)
• 3 3
 size(Array2)
• 3 10
 size(Array3)
• 2 3
 size(angels)
• 1 101
Initializing and Assigning Arrays

 Some useful MATLAB built-in functions:


 length(Array)
 Returns the length of the vector, or the longest dimension of a 2-D array
 Examples
 length(Array1)
• 3
 length(Array2)
• 10
 length(Array3)
• 3
 length(angels)
• 101

 Important Note: ALL the built-in functions in MATLAB start


with lower case
 length NOT Length
 size NOT Size
Multidimensional Arrays

 Sometimes in an application, you need to define a


Matrix with more than 2 dimensions to store the
data for further processing:
 Examples:
 You have 3 cities, with 5 temperature readings a day over a full
week
 You have 10 patients, with 3 ECG Leads sampled at 200
samples/second
 You have 10 sections of MRI images of the brain, with each image
having a 480×480 resolution
 You have 10 sections of MRI images of the brain, with each image
having a 480×480 resolution for 20 patients
Multidimensional Arrays

 The type of data you have is what defines the


dimension of the data, and not vice versa:
 Solution to the previous examples:
 size(Temperature)
Either
 5×7×3 or 3×5×7
 size(ECG)

3×200×10

 size(MRI1)

480×480×10

 size(MRI2)

 480×480×10×20

You might also like