Variable-size signal error

7 次查看(过去 30 天)
Dhruvit
Dhruvit 2023-8-19
Hello,
So, I wrote the code for tether dynamics in matlab script, and when I solve it using ode45 it is executing the code without any errors. However, when I am using this code in Matlab function block in Simulink it is giving me an error that my output variable is varying-size signal. So , can anyone help me with this?

回答(1 个)

Mrutyunjaya Hiremath
Simulink is stricter than MATLAB when it comes to variable sizes. In MATLAB, you can change the size of a variable at will, but in Simulink, the dimensions of signals are generally expected to be fixed. This is because Simulink models are often used for code generation and real-time execution, where dynamic memory allocation is not allowed.
If you're seeing an error related to a varying-size signal, here's what you should do:
  1. Variable Sizing: Firstly, ensure that all variables you are using in your MATLAB function block have a fixed size. If you're declaring matrices or vectors, their sizes shouldn't change throughout the code.
  2. Ode45: ODE solvers, like ode45, often return varying-size outputs based on their adaptive step size. This could be a problem in Simulink.
  • Consider setting the 'MaxStep' option of ode45 to ensure the number of steps does not exceed a certain limit.
  • Or use a fixed step solver like ode4 (Runge-Kutta) if appropriate for your problem.
Alternative :
  • If it's not strictly necessary to solve the ODE inside Simulink, solve it in MATLAB and import the results into Simulink as needed.
  • Consider using the built-in ODE solvers in Simulink. For example, use the "From Workspace" block to provide inputs to the system, and the "To Workspace" block to retrieve outputs.
  7 个评论
Walter Roberson
Walter Roberson 2023-8-21
Did you pre-allocate all arrays?
Are you using event functions?
Walter Roberson
Walter Roberson 2023-8-21
It would not astonish me if ode45() is just considered too complex to analyze statically, and so effectively could not be run inside a MATLAB Function Block unless dynamic memory allocation is enabled.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Verification 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by