%% Express Array Elements as Ratios
% Create a 4-by-4 matrix.

format short;
X = hilb(4)

%
% Express the elements of X as ratios of small integers using rat.

[N,D] = rat(X)

% The two matrices, N and D, approximate X with N./D.
%
% View the elements of X as ratios using format rational.

format rational
X

% In this form, it is clear that N contains the numerators of each fraction and D contains the denominators.
% Copyright 2012 The MathWorks, Inc.