MATLAB: Display rational numbers using fprintf

fprintf

I am using fprintf to write my answers to a file. I have numbers such as: 3/7,3/11,6/37… I tried different formats but every time it always changed it to a numeric value. Then I tried format rat before fprintf. This didn't work neither. How can I display a rational number using fprintf?

Best Answer

T = 1/3;
fprintf('The number is: %s\n',strtrim(rats(T)))