Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bc8db47a authored by DIB Elian's avatar DIB Elian
Browse files

Renamed normMat to normalize, fixed and simplified other functions

parent 359abaa0
No related branches found
No related tags found
No related merge requests found
function [range,nbits,castTypename] = getRange(typename)
function [range,nbits,casttypename] = getRange(typename)
%GETRANGE Summary of this function goes here
% Detailed explanation goes here
[type,nbits,castTypename] = utils.precision(typename);
[typename,nbits,casttypename] = utils.precision(typename);
switch type
switch typename
case {'ubit','uint'}
range = [0 2^nbits-1];
case {'bit','int'}
case { 'bit', 'int'}
range = [-2^(nbits-1) 2^(nbits-1)-1];
otherwise
range = [0 1];
end
end
end
\ No newline at end of file
function [A,rA] = normMat(A)
%NORMMAT Summary of this function goes here
function [A,rA] = normalize(A)
%NORMALIZE Summary of this function goes here
% Detailed explanation goes here
rA = [min(A(:)) max(A(:))];
......
function [type,nbits,castTypename] = precision(typename)
function [typename,nbits,casttypename,castnbits] = precision(typename)
%PRECISION Summary of this function goes here
% Detailed explanation goes here
types = {'bit','ubit','int','uint','float','single','double'};
expression = '\D+';
expression = '(?<type>\D+)(?<nbits>\d*)';
[type,nbits] = regexp(typename,expression,'match','split');
names = regexp(typename,expression,'names');
typename = names.type;
nbits = str2double(names.nbits);
type = type{1};
nbits = str2double(nbits{2});
if isnan(nbits)
switch type
case {'bit','ubit','int','uint'}
nbits = 8;
switch typename
case {'float','single'}
nbits = 32;
case 'double'
nbits = 64;
otherwise
error('Incorrect input type');
end
end
switch type
case {'bit','ubit'}
allowed = 1:64;
case {'int','uint'}
allowed = 2.^(3:6);
case 'float'
allowed = [32,64];
case 'single'
allowed = 32;
case 'double'
allowed = 64;
otherwise
error('Unexpected type');
end
allowed = allowed(allowed>=nbits);
nbits = allowed(1);
p = inputParser;
p.addRequired('type' ,@(type) any(strcmp(type,types)) );
p.addRequired('nbits',@(n) isscalar(n)&n>=1&n<=64 );
p.parse(type,nbits);
allowed = 2.^(3:6);
allowed = allowed(allowed>=nbits);
castNbits = allowed(1);
castTypename = typename;
switch type
case { 'bit'}
castTypename = [ 'int',num2str(castNbits)];
case {'ubit'}
castTypename = ['uint',num2str(castNbits)];
end
integernbits = [8,16,32,64];
integernbits = integernbits(integernbits>=nbits);
castnbits = num2str(integernbits(1));
switch typename
case {'ubit','uint'}
casttypename = ['uint',castnbits];
case { 'bit', 'int'}
casttypename = [ 'int',castnbits];
otherwise
casttypename = typename;
end
end
\ No newline at end of file
......@@ -3,8 +3,8 @@ function outMat = recast(inMat,varargin)
% Detailed explanation goes here
p = inputParser;
p.addOptional('outTypename','double' ,@ischar);
p.addOptional( 'inTypename',class(inMat),@ischar);
p.addOptional('outTypename', class(inMat), @ischar);
p.addOptional( 'inTypename', class(inMat), @ischar);
p.parse(varargin{:});
......@@ -14,5 +14,7 @@ outTypename = p.Results.outTypename;
inRange = utils.getRange( inTypename);
[outRange,~,outTypename] = utils.getRange(outTypename);
outMat = cast(outRange(1)+diff(outRange)*(double(inMat)-inRange(1))/diff(inRange),outTypename);
end
outMat = outRange(1)+diff(outRange)*(double(inMat)-inRange(1))/diff(inRange);
outMat = cast(outMat,outTypename);
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment