How do I display the binary value of a fixed-point FI object with the radix point in the right place, in Fixed-Point Toolbox 3.3 (R2011a)?

39 次查看(过去 30 天)
I have created a fixed-point object with a specified value, word length, and fraction length using the FI command. I would like to display the fixed-point number in binary form with the radix point in the right place, such that all the numbers to the right of the decimal point correspond to the fractional part of the number.
For example, if the binary value is 1100100100010000, with a word length of 16 and a fraction length of 14, I would like to display it as the following:
11.00100100010000
How do I do this in Fixed-Point Toolbox 3.3 (R2011a)?

采纳的回答

MathWorks Support Team
The fixed-point object has several properties that can be used to accomplish this task: 'bin', which provides the binary representation of the number as a string, 'WordLength', provides the word length, and 'FractionLength', which provides the fraction length.
By using some string operations, you can format a string such that the radix point appears in the right place. Please see the code below for an example of how to do this.
clear;
clc;
v = pi;
s = 0;
w = 16;
f = 14;
foo = fi(v,s,w,f);
rawstr = foo.bin;
pointIndex = foo.WordLength - foo.FractionLength;
str1 = rawstr(1:pointIndex);
str2 = '.';
str3 = rawstr(pointIndex+1:end);
outstr = [str1 str2 str3];
disp(foo.bin)
disp(outstr)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Designer 的更多信息

标签

产品


版本

R2011a

Community Treasure Hunt

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

Start Hunting!

Translated by