with
format long;x=1:10
=
1 2 3 4 5 6 7 8 9 10
vpa only adds one zero:
y=vpa(x,5)
=
[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
y=vpa(x,10)
=
[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
floating point boundaries (without vpa):
flintmax
=
9.007199254740992e+15
intmax
=
2147483647
intmin
=
-2147483648
you get more than 4 zeros:
a = fi(pi, 1, 8, 3)
a =
3.125000000000000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 3
but only if it is rounding non-zero decimals:
a = fi(1, 1, 8, 3)
=
1
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 3
a = fi(1.0000, 1, 8, 3)
=
1
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 3
tried 1.0001 and then -0001 but did not work:
b = fi(1.0001, 1) b = 1.000122070312500
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 14
b-.0001
Warning: The behavior of adding or subtracting a fi and a non-fi operand has
changed. The non-fi operand is now cast to the data type of the fi operand.
See the release notes for information on retaining the old behavior of best
precision scaling cast. In - (line 37)
=
1
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 17
FractionLength: 14
c=b-.0001 = 1
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 17
FractionLength: 14
b2=fi(0.0001,1)
=
1.000016927719116e-04
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 28
b-b2 = 1.000022068619728
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 31
FractionLength: 28
d=b-b2 = 1.000022068619728
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 31
FractionLength: 28
d2=vpa(d,4)
=
1.0
If you really want to present the vector exactly with 4 zero decimals, you can translate each figure to char,
x=[1:1:4]
x_char=char(x+48)'
=
1
2
3
4
and then add '.000'
x2=repmat(['.0000'],4,1)
=
.0000
.0000
.0000
.0000
x_char=[x_char x2]
=
1.0000
2.0000
3.0000
4.0000
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
Best Answer