1
votes

I have a parameter in my simulink mask: refName. In the Mask Initialization tab, I first initialize it as a 1 x 300 vector of type double. I have to do this because this vector is further propagated to a C++ S-Function, where the arrays cannot (easily) be of variable sizes.

After this, in the same initialization tab, it is assigned a value based on the user's input of another parameter refType. So, for example, if refType is 'R32', refName might be [1 2 3] (not all 300 cells are used), if refType is R410A, refName might be [4 5 6] and so on.

The problem I am having is in trying to send this variable to the workspace (as a variable refNameU) before simulation starts. I tried setting refNameU = get_param(gcb,'refName') in the CloseFcn, InitFcn and LoadFcn block callbacks, but for some reason, the value in the workspace is always zero regardless of which callback it gets called from. And not a vector of size 300 with all zeros, but just zero.

For reference, I have the 'Evaluate', 'Enable Parameter' and 'Tunable' options for the refName parameter all checked. Could someone explain to me what I am doing wrong and how I can solve this problem? Thanks in advance.

1
Why do you say it's not easy to handle different array sizes with S-Functions? You should be able to get all the info you need using mxGetNumberOfDimensions, mxGetM, mxGetN etc.Praetorian
@Praetorian You're probably right. However, my experience level with Simulink isn't extensive, so I just used the most straightforward method I knew. Basically, I had some Matlab code that I converted to a C++ S-Function first by using the Matlab Coder and then using the Legacy Code compilation process.user2215426

1 Answers

0
votes

Use assignin within the CloseFcn callback to assign the variable in the base workspace.

assignin('base', 'refNameU', refName);