Display "fixdt" data type in Simulink format

20 views (last 30 days)
Hi!
Is there is way to convert a data type information from 'fixdt(1,16,0)' format to the compiled Simulink data type format?
'fixdt(1,16,0)' --> 'int16'
fixdt(0,16,-5)' --> 'ufix16_E5'
'fixdt(1,5,12)' --> 'sfix5_En12'
I would like to get a simulink.parameter variable data type in this form.
Thanks!

Accepted Answer

Abhijeet
Abhijeet on 5 Apr 2023
Hi,
You can convert the data type information from 'fixdt(1,16,0)' format to the compiled Simulink data type format using the following rules:
  1. If the first argument of the fixdt() function is 0, the Simulink data type format will start with 'u', which means unsigned. If the first argument is 1, the Simulink data type format will start with 's', which means signed.
  2. The second argument of the fixdt() function specifies the number of bits in the data type. This can be directly translated to the Simulink data type format as 'intN' or 'uintN', depending on the sign of the data type.
  3. The third argument of the fixdt() function specifies the position of the binary point. If this value is positive, it means the binary point is to the right of the least significant bit, and the Simulink data type format should be suffixed with '_En', where N is the absolute value of the third argument. If the value is negative, it means the binary point is to the left of the most significant bit, and the Simulink data type format should be suffixed with '_E', followed by the absolute value of the third argument.
For more information you can refer to the documentation - Fixdt
Hope this resolves your query.
  1 Comment
aida_p
aida_p on 5 Apr 2023
I was hoping there is a built-in function that does this conversion, but knowing there isnt one, I will just write my own. :) Thanks for the reply.

Sign in to comment.

More Answers (1)

Alexander Carmeli
Alexander Carmeli on 13 Jun 2023
Edited: Alexander Carmeli on 13 Jun 2023
The tostringInternalSlName() method does exactly that:
fixdt(1, 16, 0).tostringInternalSlName
ans = 'int16'
fixdt(0, 16, -5).tostringInternalSlName
ans = 'ufix16_E5'
fixdt(1, 5, 12).tostringInternalSlName
ans = 'sfix5_En12'
You can find it on embedded.numerictype, and it works on Simulink.NumericType (what fixdt() produces) too.
methods(embedded.numerictype)
Methods for class embedded.numerictype: SetBestFractionLength getChildren getParent isHierarchyReadonly isboolean propertyHyperlink SetBestPrecisionForMxArray getCommonProperties getPossibleProperties isHierarchySimulating isdouble qpointstr abs getContext getPreferredProperties isLibrary isequivalent range acceptDrop getContextMenu getPropAllowedValues isLinked isfixed rmiGetString areChildrenOrdered getCurrentDialogPrompts getPropDataType isMasked isfloat rmiIsSupported areDescendentsReadonly getDialogProxy getPropValue isMatrix ishalf rmiSetString canAcceptDrop getDialogSchema getPropertyActions isModelReference isnumerictype set canAcceptMouseDrop getDialogSource getSpecifiedSign isNumeric ispropequal setPropValue castLike getDisplayClass getWidth isObserverReference isscaleddouble showChildrenInListView closeEditor getDisplayIcon hasPropertyActions isOpaque isscaledtype sqrt ctranspose getDisplayLabel indicesToUnload isPointer isscalingbinarypoint supportsIncrementalLoading delete getDisplayToRealProperty isClass isReadonlyProperty isscalingslopebias tostring disp getDropOperations isComplex isScalar isscalingunspecified tostringInternalFixdt divide getForwardedObject isDragAllowed isSimd issingle tostringInternalSlName doDropOperation getFullName isDropAllowed isStructure isslopebiasscaled transpose eps getHierarchicalChildren isEditableProperty isTunableProperty isslopebiasscalingset upperbound evalDialogParams getInfoForIncrementalLoading isEnum isValidProperty lowerbound view exploreAction getInstanceProperties isHiddenObject isVoid lsb getActionIcon getMimeData isHierarchical isanyfloat openEditor getCheckableProperty getMimeType isHierarchyBuilding isbinarypointscalingset openvar

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!