Display "fixdt" data type in Simulink format

조회 수: 16 (최근 30일)
aida_p
aida_p 2023년 3월 16일
편집: Alexander Carmeli 2023년 6월 13일
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!

채택된 답변

Abhijeet
Abhijeet 2023년 4월 5일
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
aida_p
aida_p 2023년 4월 5일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alexander Carmeli
Alexander Carmeli 2023년 6월 13일
편집: Alexander Carmeli 2023년 6월 13일
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

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by