Main Content

sym2cell

Convert symbolic array to cell array

Description

C = sym2cell(S) converts a symbolic array S to a cell array C. The resulting cell array has the same size and dimensions as the input symbolic array.

example

Examples

collapse all

Convert a matrix of symbolic variables and numbers to a cell array.

Create the following symbolic matrix.

syms x y
S =  [x 2 3 4; y 6 7 8; 9 10 11 12]
S = 

(x234y6789101112)

Convert this matrix to a cell array by using sym2cell. The size of the resulting cell array corresponds to the size of the input matrix. Each cell contains an element of the symbolic matrix S.

C = sym2cell(S)
C=3×4 cell array
    {[x]}    {[2 ]}    {[3 ]}    {[4 ]}
    {[y]}    {[6 ]}    {[7 ]}    {[8 ]}
    {[9]}    {[10]}    {[11]}    {[12]}

To access an element in each cell, use curly braces.

[C{1,1:4}]
ans = (x234)
[C{1:3,1}]
ans = (xy9)

Input Arguments

collapse all

Input symbolic array, specified as a symbolic vector, matrix, or multidimensional array. S also can be a scalar, that is, a symbolic number, variable, expression, or function.

Output Arguments

collapse all

Resulting cell array, returned as a cell array such that size(C) = size(S). Each element of the input symbolic array S is enclosed in a separate cell.

Version History

Introduced in R2016a