is there a way to define 'fixdt' in a Matlab script and use this variable in a Simulink User-Defined Function?
Show older comments
Matlab script code....DT_HD_accum = fixdt(0,24,23);
Simulink User-Defined Function (compiles fine)
result_nt = numerictype(0,24,23);
but would prefer to use:
result_nt = numerictype(DT_HD_accum);
error: Undefined function or variable 'DT_HD_accum'.
For code generation, all variables must be fully defined before use.
Accepted Answer
More Answers (2)
Andy Bartlett
on 14 Feb 2024
Edited: Andy Bartlett
on 14 Feb 2024
Inside the Simulink Library "User Defined Functions" section, there are about 16 different kinds of blocks. I'm guessing you are talking about the MATLAB Function Block kind.
If that guess is correct, this information may help.
MATLAB code inside a MATLAB Function Block or called by that code is handled by MathWorks code generation technologies even for simulation. Those technologies place some restrictions on the use of numerictype and fixdt.
Neither fixdt nor numerictype can be function argument, use dummy var instead
I believe neither numeric type object can be an input or output argument of a MATLAB function being handled by code generation technologies. The technique to pass numeric type information in or out of these functions is to create a dummy constant variable.
dummyVarToHoldDataType = fi( 0, numerictype( 1, 8, 7 ) )
numerictype OK in body, but not fixdt, until R2024a
Inside the body of the MATLAB function being handled by coder technologies you can create numerictype variables. But again, I believe these can't cross function boundaries, that variable needs to stay inside that function body.
Suppose you passed numeric type information into a function using a dummy variable, you could then extract that information to a numerictype object using this utility.
nt = fixed.extractNumericType(dummyVarToHoldDataType)
FYI: fixed.extractNumericType can support many other types of inputs.
help fixed.extractNumericType
In R2023b and earlier, a fixdt object cannot be used inside the body of a function being handled by coder technologies.
Once R2024a ships, that restriction on fixdt will be removed.
David Forey
on 13 Feb 2024
0 votes
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!