The second input to coder.internal.reallocDynamicMatrix must be indexInt.
19 views (last 30 days)
Show older comments
I was trying to solve a granulation process in simulink but the following error comes up, "The second input to coder.internal.reallocDynamicMatrix must be indexInt."
I don't have any idea on how to solve it, i am attching the files used.Please help me solve it.

5 Comments
FabianJ
on 15 Nov 2022
I have the same problem with a triggered subsystem and e.g. ode45 in a matlab function. If I run the function in the workspace, it works fine. R2021b with all updates.
Answers (1)
Süleyman Enes
on 5 May 2025
ı also encounter the same error for a problem in which ı was trying to solve an ODE set inside a matlab function block in simulink. I think this error occurs because ode solvers use dynamic matrices to solve problems more efficiently which leads different matrix sizes at each solution step. So in simulink level during to code generation system could not understood the size of the matrix.Then this error show up. Additionally, from my trials I also realize this problem depend the matlab function block architecture like that:

My case was like rightmost figure and I solve this problem by defining a fixed time step vector for solver call like below.
num_fixed_points = #; % intervals that you divide your step size -->15 for my case
t_fixed = linspace(0, t_st_s, num_fixed_points); % step time vector / t_st_s: step length--> 0.5sec for my case
options = odeset('RelTol', 1e-4, 'AbsTol', 1e-5); %ode solution options
[~, T_fixed] = ode15s(F, t_fixed, T_init, options); %solver call
since step size intervals are fixed, code generation error is vanish and model is compiled.Besides since required tolerances defined in options, during simulation if tolerances are not satisfied, fixed stepsize definition is ignored and matlab extend your solution matrix. In the end even if you define fixed number steps you get correct results.
note: coder.extrinsic(function) can also be used in less complex models ı suppose, but in my case it increase simulation time significantly
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!