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

Introduction to MATLAB

MATLAB BASICS
Variables and Arrays

 Fundamental data in MATLAB is the array


 It is organized into rows and columns
 Classified into vectors or matrices
 Size of an array is specified by the number of rows
and number of columns (m×n)
Variables and Arrays

 Most common type of variables is double


 Stored in 64-bits, double-precision floating-point
numbers
 Range is 10-308 to 10308
 15 to 16 decimal digits of accuracy
 Real, imaginary and complex

 Examples 40.2, 4i (or 4j), 40.2+4i


Variables and Arrays

 Another common variable is char


 Scalar or array of 16-bits, each representing a single
character
 Similar initialization to numbers, but we add ‘ to the
beginning and end of the string variable

 Example: comment = ‘this is a string not a number array’


Creating and Initializing Variables

 Assign data to the variable in a statement


 Input the data from the keyboard
 Read data from file [We will discuss this in detail
later on]
Creating and Initializing Variables

 Assigning Data in Statement:


 IN-CLASS Exercise

 var = 40i;

 var2 = var/5;

 x = 1; y = 2;

 array = [1 2 3 4]
Creating and Initializing Variables

 Assignment of Arrays:
 IN-CLASS Exercise

 array1 = [1 2 3;4 5 6]

 array2 = [1,2,3;4,5,6]

 array3 = [1 2 3;4 5 6]’

 array4 = array1’

 array5 = [1 2;3 4;5 6]

 array6 = [1 2 3;4 5]
Creating and Initializing Variables

 The colon “:” operand


 Structure: var = first:increment:last

default increment is 1
 var1 = 1:1:100;

 Var2= 1:100;

 x = 1:2:10

 temp_range = 0:0.01:50

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

You might also like