set non-tunable parameters to get rid of inferred variable size matrix error in simulink

조회 수: 20 (최근 30일)
I have a simulink file. And want to run a MATLAB function. Which runs fine as a script. I have then added the inputs in constant blocks in simulink and try to run it. I get the following error " 'freq' is inferred as a variable size matrix but its size is inherited or fixed. verify freq is defined in terms of non-tunable parameters or select the variable size check box and specify the upper bounds in the size box"
I am not going to change the constants during the simulation but I can't seem to get it to recognise they are non tunable parameters. I have tried taking them from the MATLAB workspace with a from workspace block. I have tried change the inputs to parameters but I can't seem to assign a value. I have tried making the permissions read only on the matlab function block. The variable size check box will not work for this sceanario
  댓글 수: 1
Umar
Umar 2024년 7월 25일

Hi Katherine,

It sounds like you made attempts to resolve the issue by using constant blocks, from workspace blocks, and changing inputs to parameters have not been successful. I would define 'freq' as a non-tunable parameter within the MATLAB Function block which can be achieved by using the coder.extrinsic function to declare 'freq' as an external variable. By doing so, you inform Simulink that 'freq' is a constant parameter and should not be treated as a variable size matrix during simulation. As an example,

coder.extrinsic('freq'); % Declare 'freq' as an external variable

function y = myMATLABFunction(x)

    % Use 'freq' as a constant parameter
    y = sin(freq*x); % Example operation using 'freq'

end

The above example code snippet should resolve the variable size matrix error during your simulation. Good luck!

댓글을 달려면 로그인하십시오.

답변 (1개)

Pramil
Pramil 2024년 8월 16일
Hi Katherine,
I have faced a similar issue. You can follow the steps mentioned in the following MATLAB answer to resolve it:
Hope it helps.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by