S = rats(X,strlen) returns
a character vector of length strlen. The rational
approximation uses a tolerance that is inversely proportional to the
length.

Find the rational representation of pi with the default character vector length and approximation tolerance. The result is the same as using format rat.

rats(pi)

ans =
355/113

Adjust the length of the output, which also adjusts the approximation tolerance.

rats(pi,20)

ans =
104348/33215

The resulting rational approximation has greater accuracy. As the output length increases, the tolerance decreases.

Adjust the output length again to achieve greater accuracy.

rats(pi,25)

ans =
1146408/364913

The resulting approximation agrees with pi to 10 decimal places.

rats obtains rational approximations with [N,D]
= rat(X,tol), where tol is min(10^(-(strlen-1)/2)*norm(X(isfinite(X)),1),.1).
Thus, the tolerance is inversely proportional to the output length, strlen.