Splitting a real number into several integers depending on position.

조회 수: 6 (최근 30일)
Lewis
Lewis 2019년 6월 18일
댓글: Lewis 2019년 6월 18일
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