Is there anyway of obtaining the numerator and denominator in MATLAB without using numden() function? For example:
format rational
x=5/2;
I want to obtain 5 as num and 2 as den. Can you help me with this tricky problem.
Is there anyway of obtaining the numerator and denominator in MATLAB without using numden() function? For example:
format rational
x=5/2;
I want to obtain 5 as num and 2 as den. Can you help me with this tricky problem.
How about
[N,D] = rat(2.5)
Otherwise, if you insist on doing it yourself, you can do something like
N = 2.5;
D=1; while (int64(N)~=N), N=N*10; D=D*10; end
g = gcd(N,D);
D = D/g;
N = N/g;