Displaying rational numbers in Matlab -
i have 2 integer numbers m,n form rational number in form of m/n. want display them in matlab in rational form.
i can doing
char(sym(m/n)) so, if, e.g. m = 1, n = 2, matlab display 1/2. however, if m = 2, n = 4, getting 1/2, whereas want 2/4.
any way of doing without recurring like
fprintf( '%d/%d', m, n ) thanks
you can change display format rat
>> format rat >> 2/3 ans = 2/3 otherwise can call rats function
>> rats(2/3) ans = 2/3 >> class(ans) ans = char however, in both cases fractions reduced. avoid should create separate function or introduce anonymous function
>> rat2 = @(m,n) num2str([m n], '%d/%d') rat2 = @(m,n)num2str([m,n],'%d/%d') >> rat2(2,4) ans = 2/4
Comments
Post a Comment