Splitting a real number into several integers depending on position.

2 次查看(过去 30 天)
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!

采纳的回答

Bob Thompson
Bob Thompson 2019-6-18
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by