The second input to coder.internal.reallocDynamicMatrix must be indexInt.
Mostrar comentarios más antiguos
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 comentarios
Yu-Chen Su
el 19 de Jun. de 2022
I have the same problem
Lukas Tarra
el 5 de Ag. de 2022
The same issue has occurred when I used ode45 in a Matlab function block within a triggered subsystem in Simulink (occurred also with other solvers, e.g. ode78).
Given that the error seems rather unrelated to my code, I am led to believe that this is a Simulink bug.
If anyone here knows what is going on, your help would be highly appreciated.
Alexandros
el 28 de Oct. de 2022
Did you manage to solve this? I am having the same problem
FabianJ
el 15 de Nov. de 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.
Tariq Limouni
el 24 de Abr. de 2023
Did anyone find the solution please? I got the same message
Respuestas (1)
Süleyman Enes
el 5 de Mayo de 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
Categorías
Más información sobre Simulink Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!