Convert cell array to symbolic array
converts
a cell array S
= cell2sym(C
)C
to a symbolic array S
.
The elements of C
must be convertible to symbolic
objects.
If each element of the input cell array C
is
a scalar, then size(S) = size(C)
, and S(k)
= sym(C(k))
for all indices k
. If the
cell array C
contains nonscalar elements, then
the contents of C
must support concatenation
into an N-dimensional rectangle. Otherwise, the results are undefined.
For example, the contents of cells in the same column must have the
same number of columns. However, they do not need to have the same
number of rows. See figure.
Convert a cell array of only scalar elements to a symbolic array.
Create a cell array of scalar elements.
C = {'x','y','z'; 1 2 3}
C = 2×3 cell array {'x'} {'y'} {'z'} {[1]} {[2]} {[3]}
Convert this cell array to a symbolic array.
S = cell2sym(C)
S = [ x, y, z] [ 1, 2, 3]
cell2sym
does not create symbolic variables x
, y
,
and z
in the MATLAB® workspace. To access an
element of S
, use parentheses.
S(1,1)
ans = x
Convert a cell array whose elements are scalars, vectors, and matrices into a symbolic array. Such conversion is possible only if the contents of the cell array can be concatenated into an N-dimensional rectangle.
Create a cell array, the elements of which are a scalar, a row vector, a column vector, and a matrix.
C = {'x' [2 3 4]; ['y'; sym(9)] [6 7 8; 10 11 12]}
C = 2×2 cell array {'x' } {1×3 double} {2×1 sym} {2×3 double}
Convert this cell array to a symbolic array.
S = cell2sym(C)
S = [ x, 2, 3, 4] [ y, 6, 7, 8] [ 9, 10, 11, 12]
When converting a cell array containing floating-point numbers, you can explicitly specify the conversion technique.
Create a cell array pi
with two elements:
the double-precision value of the constant pi
and
the exact value pi
.
C = {pi, sym(pi)}
C = 1×2 cell array {[3.1416]} {1×1 sym}
Convert this cell array to a symbolic array. By default, cell2sym
uses
the rational conversion mode. Thus, results returned by cell2sym
without
a flag are the same as results returned by cell2sym
with
the flag 'r'
.
S = cell2sym(C)
S = [ pi, pi]
S = cell2sym(C,'r')
S = [ pi, pi]
Convert the same cell array to a symbolic array using the flags 'd'
, 'e'
,
and 'f'
. See the Input Arguments section for the details about conversion
techniques.
S = cell2sym(C,'d')
S = [ 3.1415926535897931159979634685442, pi]
S = cell2sym(C,'e')
S = [ pi - (198*eps)/359, pi]
S = cell2sym(C,'f')
S = [ 884279719003555/281474976710656, pi]