Overview of MATLAB Variables: Scalars Vectors Matrices Strings
Overview of MATLAB Variables: Scalars Vectors Matrices Strings
Lesson Outcomes
At this end of the 2 hours lab, the students are expected to the abilities on:
Variables
1. Creating the suitable variables and assigning it with data
2. Modifying the existing variables with new data
3. Delete the variable from MATLAB memory
Script
1. Create a script MATLAB file (m-file) using command or MATLAB menus
2. Run the m-file
Function
1. Create an inline function to store the required function for computatation
2. Run the inline function
Plotting
creates the ``variable'' and assigns to it the value of the expression on the right
hand side. You do not need to define or declare a variable before it is used.
Matrices do not need to explicitly dimensioned, and MATLAB allows you to
increase the size of a matrix as you work.
Advanced MATLAB users will point out that the speed of MATLAB functions can
be increased by pre-allocating memory for matrices and vectors. This and other
performance considerations are discussed elsewhere.
Variable names must begin with an alphanumeric letter. Following that, any
number of letters, digits and underscores can be added, but only the first 19
characters are retained. MATLAB variable names are case sensitive so x and X are
different variables.
All numerical variables in MATLAB are matrices, a mathematical data type
corresponding to a two-dimensional array of numbers. Before performing any
calculations with a numeric variable, MATLAB prods and pokes into its contents.
MATLAB is very careful to follow the rigorous rules of linear algebra, and it only
allows legal operations between matrices, vectors and scalars.
But what about the statement that ``all numerical variables in MATLAB are
matrices''?
MATLAB keeps track of the dimension of each variable. Thus, the statement