MATLAB: Unable to perform assignment because brace indexing is not supported for variables of this type.

brace indexing is not supported for variables of this type

Hi everyone, I am trying to run this code:
clear all
close all
clc
syms x(t) y(t) z(t) A B C D E FF G H I J K LL MM N O P Q R S
eqn1 = diff(x(t),t) == 1/ A * ((B * C - B * x(t))) - (x(t) * D * E - FF*((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H))) / ((1/I) + 1/(J * (((K*(FF* x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H))))) + LL * (((G * FF * x(t) * D * E/z(t)) - ((y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)))) + MM * ((((G * H *FF* x(t) * D * E/z(t)^2) - ((y(t) * G * H)/(z(t)^2 + G * z(t) + G*H))))))) / (K * (FF * x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H)))));
eqn2 = diff(y(t),t) == (x(t) * D * E - FF*((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H))) / ((1/I) + 1/(J * (((K*(FF* x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H)) ) + LL * (((G * FF * x(t) * D * E/z(t)) - (( y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)))) + MM * ((((G * H * FF * x(t) * D * E / z(t)^2) - ((y(t) * G * H)/(z(t)^2 + G * z(t) + G * H))))))/ (K * (FF * x(t) * D * E - (( y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H))))))) - 0.162 * exp(-5153/E) * (((N * (( y(t) * G * H)/(z(t)^2 + G * z(t) + G*H)))/O) - 1)^2 * (P / ((N * (((y(t) * G * H)/(z(t)^2 + G * z(t) + G * H))))) / O));
eqn3 = z(t) + 2 * N - ((y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)) - 2 * (( y(t) * G * H)/(z(t)^2 + G * z(t) + G*H)) - ((N * Q * z(t))/(z(t)^2 + Q * z(t) + Q*R)) - 2 * ((N * Q * R)/(z(t)^2 + Q * z(t) + Q*R)) - S/z(t) == 0;
eqns = [eqn1 eqn2 eqn3];
vars = [x(t); y(t); z(t)];
origVars = length(vars);
M = incidenceMatrix(eqns, vars);
[eqns, vars] = reduceDifferentialOrder(eqns, vars);
isLowIndexDAE(eqns,vars);
f = daeFunction(eqns,vars, A, B, C, D, E, FF, G, H, I, J, K, LL, MM, N, O, P, Q, R, S);
A = 1.5e-6;
B = 1.66667e-5;
C = 6.51332e-2;
D = 8.314;
E = 323.15;
FF = 149;
G = 6.24;
H = 5.68e-5;
I = 4.14e-6;
J = 7.25E-2;
K = 2.98e-9;
LL = 2.35e-9;
MM = 1.69e-9;
N = 8;
O = 1.07e-7;
P = 10;
Q = 1.7e-3 ;
R = 6.55e-8;
S = 5.3e-8 ;
F = @(t, Y, YP) f(t, Y, YP, A, B, C, D, E, FF, G, H, I, J, K, LL, MM, N,O, P, Q, R, S);
vars;
y0est = [4.58E-02; 1.58; 1];
yp0est = zeros(3,1);
opt = odeset('RelTol', 10.0^(-7), 'AbsTol' , 10.0^(-7));
[y0, yp0] = decic(F, 0, y0est, [], yp0est, [], opt);
[tSol,ySol] = ode15i(F, [6720, 27840], y0, yp0, opt);
for k = 1:origVars
S{k} = char(vars(k));
end
However, I get the error message:
Unable to perform assignment because brace indexing is not supported for variables of this type.
Error in Example01Sept2018 (line 57)
S{k} = char(vars(k));
The Debugging points me to:
for k = 1:origVars
S{k} = char(vars(k));
end
When I change to:
for k = 1:origVars
S(k) = char(vars(k));
end
I get an error message:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Example01Sept2018 (line 57)
S(k) = char(vars(k));
What can I do?

Best Answer

You have
S = 5.3e-8 ;
but later you want to use S to store the names of the variables. I do not recommend re-using the name of a numeric coefficient for something completely different: it gets too confusing.
But if it is for some reason very important to use the name S in both cases, then you will need to assign something to change S into a cell array, such as
S = cell(origVars, 1);
Or you can skip the initialization and the explicit loop and use
S = arrayfun(@char, vars, 'uniform', 0);