Convert symbolic array to cell array
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 = [ x, 2, 3, 4] [ y, 6, 7, 8] [ 9, 10, 11, 12]
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 {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym} {1×1 sym}
To access an element in each cell, use curly braces.
[C{1,1:4}]
ans = [ x, 2, 3, 4]
[C{1:3,1}]
ans = [ x, y, 9]