Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Using different data types for a 3D Table

0 votes

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!
asked Jan 24, 2022 by dr00mprins (25 points)
edited Jan 24, 2022 by dr00mprins

1 Answer

0 votes
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.
answered Feb 1, 2022 by Bryan Lieblick (1,795 points)