Effacer les filtres
Effacer les filtres

Splitting a real number into several integers depending on position.

2 vues (au cours des 30 derniers jours)
Lewis
Lewis le 18 Juin 2019
Commenté : Lewis le 18 Juin 2019
Good afternoon guys,
This seems abit confusing, but this is what i am trying to accomplish.
If i have x=0.4321
I need a way to split this real number into just single integers, so for example
x1=0, x2=4, x3=3.... and so on, with the number after the 'x' corresponding to its position in the original real number.
is there a way to do this?
To give a wider context, i will have a f(x) = 0.AB rounded down to 2dp. The actual values of A and B are the coordinates to find a value within a large matrix.
Thanks in advance for any help!

Réponse acceptée

Bob Thompson
Bob Thompson le 18 Juin 2019
Why not turn the number into a string?
y = num2str(x);
y = y(y(:)~='.'); % Remove '.'
With this you are left with the numbers following the decimal, and if you would like to call them one at a time then you can just index y.
Y = str2num(y(3));

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by