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

14 ビュー (過去 30 日間)
Aaditya Goverdhan
Aaditya Goverdhan 2021 年 7 月 8 日
回答済み: Süleyman Enes 2025 年 5 月 5 日
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 件のコメント
FabianJ
FabianJ 2022 年 11 月 15 日
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 2023 年 4 月 24 日
Did anyone find the solution please? I got the same message

サインインしてコメントする。

回答 (1 件)

Süleyman Enes
Süleyman Enes 2025 年 5 月 5 日
ı 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

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by