# How to Build a Cell Array in Matlab

Written by michael peter
• Share
• Tweet
• Share
• Email

MATLAB is a technical computing software used by scientists and engineers for data processing and analysis. Frequently data stored in arrays and matrices are manipulated using built-in MATLAB functions that include matrix addition and multiplication. Often it is necessary to store individual cells of data of different types and dimensions within a much larger container where each cell can be accessed at a later time. This is done by creating a cell array in MATLAB, which allows alphanumeric data to be stored with numeric arrays of numbers. Individual cells can be added to an already existing cell array, as well each cells pre-existing contents can be modified with new content.

Skill level:
Moderately Easy

## Instructions

1. 1

Clear all active variables within the workspace by entering "clear all" in the MATLAB Command window.

2. 2

Create a cell array of empty matrices by entering the command "x=cell(2,2)" into the Command window. This command creates a 2 row by 2 column cell array of empty matrices.

3. 3

Create a 2 row by 2 column cell array that contains data of different types by entering the command "x={'Building Arrays' ,rand(2,2); 0:1:10, 5+5i}" where the "{" and "}" specify a cell array. The "," specifies the data should be in a different column and the ";" creates a new row. In this example, the first row contains a string saying "Building Arrays" and a 2x2 matrix of random unsigned integers. The second row contains an 11 element array of unsigned intergers starting at 0 and ending at 10 and a complex number.

4. 4

Add an additional element to the cell array created in Step 3 by entering "x(2,3)={10}," which adds a new element in the 2nd row and 3rd column of the matrix "x." MATLAB automatically expands the cell array by placing an empty matrix in the 1st row 3rd column of the cell array.

#### Tips and warnings

• Create an empty square array using the command "x=cell(2)," which creates a 2 row by 2 column square array of empty matrices.

### Don't Miss

#### References

• All types
• Articles
• Slideshows
• Videos
##### Sort:
• Most relevant
• Most popular
• Most recent

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.