home *** CD-ROM | disk | FTP | other *** search
- function S = rats(X,lens)
- %RATS Rational output.
- % RATS(X,LENS) uses RAT to display rational approximations to
- % the elements of X. The string length for each element is LENS.
- % The default is LENS = 13, which allows 6 elements in 78 spaces.
- % Asterisks are used for elements which can't be printed in the
- % alloted space, but which are not negligible compared to the other
- % elements in X.
- %
- % The same algorithm, with the default LENS, is used internally
- % by MATLAB for FORMAT RAT.
- %
- % See also FORMAT, RAT.
-
- % Cleve Moler, 10-28-90.
- % Copyright (c) 1984-93 by The MathWorks, Inc.
-
- if nargin < 2, lens = 13; end
- lhalf = fix(lens/2);
- tol = 10^(-lhalf) * norm(X(:),1);
- [N,D] = rat(X,tol);
- [m,n] = size(X);
- S = [];
- nform = ['%' num2str(lhalf) '.0f'];
- dform = ['%-' num2str(lhalf) '.0f'];
- for i = 1:m
- s = [];
- for j = 1:n
- sj = sprintf(nform,N(i,j));
- if D(i,j) ~= 1
- sj = [sj '/' sprintf(dform,D(i,j))];
- else
- sj = [' ' sj ' '];
- end
- s = [s sj];
- end
- S(i,:) = s;
- end
-