The second input to coder.inte​rnal.reall​ocDynamicM​atrix must be indexInt.

19 vues (au cours des 30 derniers jours)
Aaditya Goverdhan
Aaditya Goverdhan le 8 Juil 2021
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 commentaires
FabianJ
FabianJ le 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.
Tariq Limouni
Tariq Limouni le 24 Avr 2023
Did anyone find the solution please? I got the same message

Connectez-vous pour commenter.

Réponses (1)

Süleyman Enes
Süleyman Enes le 5 Mai 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

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by