# How can I create a row of numbers form 1 to 10 ?. like this [1.0000, 2.0000, 3.0000,...]?

854 views (last 30 days)

Show older comments

Chinonso Collins Unaichi
on 3 May 2016

Commented: Chinonso Collins Unaichi
on 3 May 2016

##### 0 Comments

### Accepted Answer

John BG
on 3 May 2016

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

with fixed point precision objects, details here: http://uk.mathworks.com/help/fixedpoint/ref/fi.html?searchHighlight=fi

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

### More Answers (1)

Alessandro Masullo
on 3 May 2016

Matlab deals with double variables by default. If you write 1, it is actually 1.00000000

If you just want to display it, you can use sprintf('%.5f',1).

To check your variable type, you can use whos

##### 2 Comments

Alessandro Masullo
on 3 May 2016

Yes, you're right. The only real difference comes when you specify the variable type:

K>> format shorteng

K>> double(1:5)

ans =

1.0000e+000 2.0000e+000 3.0000e+000 4.0000e+000 5.0000e+000

K>> uint8(1:5)

ans =

1 2 3 4 5

### See Also

### Community Treasure Hunt

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

Start Hunting!