Splitting a real number into several integers depending on position.

6 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Bob Thompson
Bob Thompson am 18 Jun. 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));

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by