function y = binary(d,n)
% BINARY y = binary(d,n) Integers to binary equivalents
% Version of 7/14/95
% Converts a matrix d of floating point, nonnegative
% integers to a matrix of binary equivalents. Each row
% is the binary equivalent (n places) of one number.
% Adapted from the programs dec2bin.m, which shared
% first prize in an April 95 Mathworks contest.
% Winning authors: Hans Olsson from Lund, Sweden,
% and Simon Cooke from Glasgow, UK.
% Each matrix row may be converted to an unspaced string
% of zeros and ones by the device: ys = setstr(y + '0').
if nargin < 2, n = 1; end % Allows omission of argument n
[f,e] = log2(d);
n = max(max(max(e)),n);
y = rem(floor(d(:)*pow2(1-n:0)),2);