is there a way to define 'fixdt' in a Matlab script and use this variable in a Simulink User-Defined Function?
9 views (last 30 days)
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.
0 Comments
Accepted Answer
Kiran Kintali
on 13 Feb 2024
Can you share a bit more details of this usecase?
A sample model would be helpful. Are you using this in the context of a MATLAB function block?
I see you tagged Simulink and HDL Coder products, I am assuming you would like to generate HDL from such model.
0 Comments
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!