More MATLAB Basics: strings, mathematical operations, plotting


Strings

color1 = 'blue'

color2 = 'green'

text = 'to embed an apostrophe isn''t hard'

combo = [color2, '-', color1]

combo(length(combo) + 1) = 's'

ch = combo(7)

combo(7:end) = 'black'


Mathematical Operations on Vectors and Matrices

Arithmetic operators

+   -   *   /   ^   \

Operators use rules of linear algebra:

Element-wise operation

 

 

 

 

 

 

 








Basic Plotting

plot( xcoords, ycoords, 'spec' )

Example: plot y = 4x2cos(x) - 3x + 7 over the range x = 2 to 30

 

 

 

 

Example: plot the points (1,1), (3,4), (5,8), (2,9), (7,2)

 

 

 

 

Plotting multiple sets of data:

plot( xcoords1, ycoords1, 'spec1', xcoords2, ycoords2, 'spec2' )

Example: plot y = cos(x) and y = 0.5x2 - 2x + 1 for x = 0 to 3π

 

 

 

 

 

 

 

Additional features: