One way to achieve this is to use the Mask Initialization code to create a dummy "value holder variable" of the same type specified by the dialog parameter. Then pass that dummy "value holder variable" as a parameter into the MATLAB Function block.
For example, if the mask dialog parameter specifies the data type 'single', then create dummyVarToCarryDesiredType = single(0). Note the value held by this dummy variable is unimportant. I used the value 0 as an example, but it could just as well have been 54.32. What matters is the type of the value holder, not its value.
As another example, if the mask dialog parameter specifies the data type 'fixdt(1,8,3)', then create dummyVarToCarryDesiredType = fi(0,1,8,3).
Once you get the dummy variable passed inside the MATLAB Function block, you can get the type information from the dummy and do the desired operations. I've attached an example library block that does a cast operation.
Inside the MATLAB Function block code for this example, the elegant cast-like syntax is used.
function y = fcn(u,dummyVarToCarryDesiredType)
y = cast( u, 'like', dummyVarToCarryDesiredType);
Open the mask editor on this block to see how the rest works.
I've written this example to be polymorphic to all numerictypes: double, single, logical/boolean, int8, ... uint64, all fixed-point types, and half.
A key to the approach is the Mask Initialization code.
numericTypeFromMask1 = fixed.extractNumericType(dtOut);
if ishalf(numericTypeFromMask1)
dummyVarToCarryDesiredType = half(0);
temp1 = fi(0,numericTypeFromMask1);
temp2 = castFiToMATLAB(temp1);
dummyVarToCarryDesiredType = castIntToFi(temp2);
numericTypeForMLFBParam = numericTypeFromMask1;
maskIconTypeStr = numericTypeFromMask1.tostringInternalFixdt;
numericTypeForMLFBParam = numericTypeFromMask1.tostringInternalSlName;
maskIconTypeStr = numericTypeForMLFBParam;
Here is a screenshot of it working with all base MATLAB types.
Here is a screenshot of it working with fixed-point and half.
Both example models (using Release R2021a) are attached.
The first example simulates with just base Simulink.
The second example will also require Fixed-Point Designer license to simulate.