Error: output is inferred as a variable-size matrix, but its size is specified as inherited or fixed.

198 次查看(过去 30 天)
To simplify the question, when I define the size of my output based on a constant input (it won't change during the simulation), i receive the following error: 'y' is inferred as a variable-size matrix, but its size is specified as inherited or fixed. Verify 'y' is defined in terms of non-tunable parameters, or select the 'Variable Size' check box and specify the upper bounds in the Size box.
Other people had this problem but I couldn't really find a way to fix it. I can't select the variable size check box because it lead to other errors. I also don't have the coder library. I got that in theory this constant value can me modified and then cause problems, but it isn't my case, I just want to define it when the simulation starts.
function y = fcn(u)
y = zeros(u,1);

回答(2 个)

arushi
arushi 2024-8-12
Hi Rodrigo,
To address the error you're encountering in Simulink when defining the size of your output based on a constant input, you need to ensure that Simulink can recognize the size as fixed during the simulation. Here's a step-by-step guide to achieve this without needing the coder library or variable-size settings.Step-by-Step Solution
  1. Define the Constant Parameter in the Base Workspace: Ensure that the constant parameter that determines the size is defined in the base workspace or as a model parameter. For example, define N in the base workspace.
  2. Use a MATLAB Function Block: Use a MATLAB Function block in Simulink and ensure that the size parameter is passed as an argument to the function.
  3. Declare the Parameter as Constant: Inside the MATLAB Function block, declare the size parameter as constant using the coder.const function (if available) or simply ensure it's treated as a constant.
Hope this helps.

Pramil
Pramil 2024-8-12
编辑:Pramil 2024-8-12
The output yhas a size that depends on the input data “u. Simulink assumes the output to be of variable size. However, the output signal is not configured as variable size as the error suggests.
Since, the value of “u” does not change and “y” remains constant throughout the simulation, you can define “u” as a block parameter.
You can do this by following these steps:
  • Double click your “MATLAB Function block”.
  • Go to MODELING->Symbols Pane, a side window with variables will be opened.
  • Now select “u” and left click on it, mark it as “Parameter Data”.
  • Go to SIMULATION tab and click on property Inspector and make sure that for “u, the “Tunable” check box is unchecked.
Now you can define “u, anywhere either in your base workspace or model workspace, it should just work fine.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by