Question

With the fixed-point license it is easy to create arbitrary fixed-point data types in Matlab ie a signed 32 bit number with 16 fractional bits:

custom_sfix = fixdt(1,32,16)

custom_sfix =

Simulink.NumericType
    DataTypeMode: 'Fixed-point: binary point scaling'
      Signedness: 'Signed'
      WordLength: 32
  FractionLength: 16
         IsAlias: false
       DataScope: 'Auto'
      HeaderFile: ''
     Description: ''

How do I create a value of this type in matlab?

For built in types it is just a = int8(5); or a = uint32(45); I have also tried types cast, but this only seems to accept the built in datatypes.

>> Y = typecast(12.5, custom_sfix )
Error using typecast
The second input argument must be a character array.

>> Y = typecast(12.5, 'fixdt(1,32,16)' )
Error using typecast
Unsupported class.
Était-ce utile?

La solution

I believe fixdt is for creating fixed-point data type signals in Simulink, rather than MATLAB. You would then define your signal to be of that data type as shown in http://www.mathworks.co.uk/help/simulink/ug/working-with-data-types.html#f14-90565.

If you want to create fixed-point objects in MATLAB, you probably want to use fi instead. There are casting examples in the doc too.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top