This article covers how to create matrices, vectors, and cell arrays with the programming software MATLAB. Since MATLAB is a program offering endless possibilities, being able to understand the basics will lead to the ability to write more complex codes later on. No previous knowledge of MATLAB is required for these instructions.

Part 1
Part 1 of 4:
Creating Matrices

  1. 1
  2. 2
    Create a one value matrix. Type commands such as zeros or ones to create a matrix with only one value within it. Follow these commands by the number of rows then the number of columns separated by a comma and surrounded by parenthesis.
    Advertisement

Part 2
Part 2 of 4:
Creating Vectors

  1. 1
  2. 2
  3. 3
    Create a one value vector. Type commands such as zeros or ones to create a horizontal or vertical vector with only one value within it. Follow these commands by the number of rows then the number of columns separated by a comma and surrounded by parenthesis.
  4. 4
    Create a vector with a pattern. A pattern is a list of numbers that follow a certain rule or sequence. Type the colon operator or the linspace command. A colon operator focuses on a specific increment that the pattern follows while the linspace command focuses on the number of variables within the pattern that are have the same increment between them.
    Advertisement

Part 3
Part 3 of 4:
Creating Cell Arrays

  1. 1
  2. 2
    Advertisement

Part 4
Part 4 of 4:
Avoiding Common Errors

  1. 1
    Ensure that all commands are in lowercase letters.
  2. 2
    Ensure that the Matrix has the same number of variables in each column.
  3. 3
  4. 4
    Ensure that the Cell Array has curly brackets { } enclosing it.
  5. 5
  6. 6
    Advertisement

Community Q&A

  • Question
    How to construct this column matrix [ 10 100 1000 100000 1000000]?
    Daniel
    Daniel
    Community Answer
    You've already completed step one of arranging the set of data in a matrix in square brackets; just arrange the numbers in rows. You can easily accomplish this using MATLAB's size() function. Let A = [10 100 1000 100000 1000000]. That will be the variable for the matrix. Now you're just a "sz = size(A)" away. You may be familiar with size() if you've used arrays in MATLAB, but it works the same with matrices!

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 9 people, some anonymous, worked to edit and improve it over time. This article has been viewed 42,013 times.
How helpful is this?
Co-authors: 9
Updated: August 29, 2018
Views: 42,013
Categories: Featured Articles | MATLAB
Advertisement