function c = integerize(A)
%Input matrix A of non-negative integers
%Output c is smallest unsigned integer class
%Example: A = 256
% c = integerize(A)
s = max(A(:)); %maximum element of A
if s>=0 && s< 2^8
c = 'uint8';
elseif s>=0 && s< 2^16
c = 'uint16';
elseif s>=0 && s< 2^32
c = 'uint32';
elseif s>=0 && s< 2^64
c = 'uint64';
else
c = 'NONE';
end
Search Program on this blog
Wednesday, 19 August 2015
Write a function called integerize that takes as its input a matrix A of non-negative integers of type double, and returns the name of the “smallest” unsigned integer class to which A can be accurately converted. If no such class exists, the string 'NONE' is returned. For example, if the largest element of A is 14, then the function would return 'uint8', but if the largest integer in A is 1e20, then the function would return 'NONE'.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment