I am currently working on an S-Function in Simulink, and I encountered the following error:

3 次查看(过去 30 天)
Error: Cannot initialize the width of data type work vector 1 of 'untitled/S-Function'. The data type work vector width is set to dynamically sized (-1). Initialize the data type work vector width in mdlInitializeSizes or mdlSetWorkWidths.
I understand that the issue is related to initializing the width of the data type work vector. However, I am unsure about the steps to resolve this error. Could you please provide guidance on how to initialize the data type work vector width in either mdlInitializeSizes or mdlSetWorkWidths?

回答(1 个)

Ayush Singh
Ayush Singh 2024-2-12
Hi Ahraz
In order to initialize the width of data type work vector using mdlInitializeSizes try adding this code
static void mdlInitializeSizes(SimStruct *S)
{
% Add mdlInitializeSizes code here *
% Register the number of DWork vectors
ssSetNumDWork(S, 1); % This sets the number of DWork vectors to 1
% Set the width of the first (and only) DWork vector
ssSetDWorkWidth(S, 0, 10); % This sets the width of the first DWork vector to 10
}
Here 'S' is SimStruct representing an S-Function block.
For more information on 'mdlInitializeSizes' , 'ssSetNumDWork' and 'ssSetDWorkWidth' refer to following links:
I hope the above information helps!

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by