Hi,
I have tables/arrays with different data types (double precision, single precision, half precision, uint8, …) stored in the Matlab workspace.
I want to use these different data types in the PLECS 3D-Table and compare the results. For the default 64 bit (double precision) it works fine. For the other data types, I get a compilation error like: “3D array contains infinite elements.”
I saw, that PLECS offers the possibility to change the data type via a separate block “Data Type” within the PLECS simulation.
But is it not possible to choose the data type already in the Matlab Workspace which I would prefer because of the half precision which is obviously not possible in PLECS?
Or what’s the problem here? Thank you!
The input parameters to a PLECS Blockset model should be double precision, which is the default numeric type in Matlab. As you suggested, the Data Type block is one solution to convert to the desired data format within the PLECS model. A simple function could be used to determine the data type of the input variable and automatically determine the appropriate setting for the Data Type block, when available.
There is no built-in conversion to the half precision datatype. One option would be to cast to the desired type in a C-script. There is some nuance here, as the compiler used only supports the ‘__fp16’ conversion (storage data type and not arithmetic) and the all outputs of C-Scripts are re-cast to doubles. If you are using the output of this block for further manipulation you should be aware of these limitations.
A simple demo is attached showing these basic approaches is attached. Run the “datatypes.m” file to compare the results between the Matlab workspace and PLECS/Simulink.
datatypes.m (643 Bytes)
simdatatypes.slx (28.4 KB)