How can I create a row of numbers form 1 to 10 ?. like this [1.0000, 2.0000, 3.0000,...]?
Mostra commenti meno recenti
Hallo guys, I am so new to matlab, and i know this is a silly question. How can I create a row of numbers form 1 to 10. like this [1.0000, 2.0000, 3.0000,...] with intervals of 1.0000? if I do [1:1:10], I get [1,2,3,..] but I want it like this[1.0000,2.0000,3.0000] kindly help! Thanks in advance.
Risposta accettata
Più risposte (1)
Alessandro Masullo
il 3 Mag 2016
1 voto
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 Commenti
To add to Alessandro's answer. You're confusing two different things, the number that is stored in the matrix and the way it is displayed.
In matlab and in math, there is no difference whatsoever between 1 and 1.0000. You can change the way matlab displays number in the command window with format. Most of the formats display integer without any decimal, only the engineering format always use decimal:
>>format shorteng
>>1
ans =
1.0000e+000
Or as Alessandro said, you can use the format string of sprintf to output your number to the command line.
But as said, it is just cosmetics. The numbers are the same regardless of how you display them.
Alessandro Masullo
il 3 Mag 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
Categorie
Scopri di più su Create Fixed-Point Objects in MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!