Skip to main content

4.2) Scalars


  • In Matlab, a scalar is a variable with one row and one column (2D array of size 1x1)
  • Scalars are the simplest variables that we use and manipulate in simple algebraic equations
  • Can be single real or complex numbers
  • To create a scalar you simply introduce it on the left hand side of an equals sign
  • [matlab]
    >> x = 1;
    >> y = 2;
    >> z = x + y;
    [/matlab]

  • Matlab supports the standard scalar operations using an obvious notation. The following statements demonstrate scalar addition, subtraction, multiplication and division
  • [matlab]
    >> u = 4;
    >> v = 3;
    >> w = u + v
    >> x = u * v
    >> y = u / v
    [/matlab]

  • When you previously used Matlab as a simple calculator, Matlab created a scalar value called "ans" to store your answer