📄 hxdouble.m
字号:
function hxf = hxdouble(inp)
% hxdouble - transform a double from/into a readable string
%
% doubles cannot be printed in their native "precision". hxdouble
% gives a more memory based representation so as to store the
% exact value of a number
%
% FORMAT: hxstring = hxdouble(doubles)
% or doubles = hxdouble(hxstring)
%
% Input fields:
%
% doubles an array of type double (only real numbers)
% a non-linear array will be linearized (:)'
% hxstring a 1xN char representation prior created with
% this function
%
% Output fields:
%
% hxstring the resulting string from a call to hxdouble
% doubles an 1xN double array, transformed back from a
% string representation
%
% See also any2ascii.
% Version: v0.5c
% Build: 6120415
% Date: Dec-04 2006, 3:15 PM CET
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
persistent hxd_hxi hxd_hxr;
if isempty(hxd_hxi)
tmpTest = sprintf('%bx',2);
switch tmpTest, case {'0000000000000040'}
hxd_hxi = [15:-2:1;16:-2:2];
hxd_hxi = hxd_hxi(:);
case {'4000000000000000'}
hxd_hxi = 1:16;
hxd_hxi = hxd_hxi(:);
case {'0000000000000004'}
hxd_hxi = 16:-1:1;
hxd_hxi = hxd_hxi(:);
case {'0400000000000000'}
hxd_hxi = [2:2:16;1:2:15];
hxd_hxi = hxd_hxi(:);
otherwise
error('Platform not supported!');
end
hxd_hxr = [ ...
nan * ones(1, 48) ...
0 1 2 3 4 5 6 7 8 9 nan nan nan nan nan nan ...
nan 10 11 12 13 14 15 nan nan nan nan nan nan nan nan nan ...
nan * ones(1, 16) ...
nan 10 11 12 13 14 15 nan nan nan nan nan nan nan nan nan ...
nan * ones(1,144) ...
];
end
% enough arguments ?
if nargin < 1
error( ...
'BVQXtools:TooFewArguments',...
'Too few arguments. Try ''help %s''.',...
mfilename ...
);
end
if isa(inp, 'double')
hxf = sprintf('%bx', real(inp));
ns = length(hxf) / 16;
hxi = (hxd_hxi * ones(1,ns)) + (ones(16,1) * (0:(ns-1) * 16));
hxf = hxf(hxi(:)');
elseif ischar(inp)
inp = reshape(inp, [1, numel(inp)]);
ns = floor(length(inp) / 16);
hxf = zeros(1, ns);
for hxc = 1:ns
ipp = lower(inp((hxc-1)*16+1:hxc*16));
if strcmp(ipp, 'fff8000000000000')
hxf(hxc) = NaN;
continue;
end
ipd = min(double(ipp), 255) + 1;
ipi = hxd_hxr(ipd);
if any(isnan(ipi)) || all(ipi==0)
continue;
end
iex = 256*ipi(1)+16*ipi(2)+ipi(3);
if iex > 2047
isg = -1;
iex = iex - 2048;
else
isg = 1;
end
imt = 0;
for mtc = 4:16
imt = imt*16+ipi(mtc);
end
if iex > 64
hxf(hxc) = 2.^(iex-1023) + (2.^(iex-1075)).*imt;
elseif iex > 0
hxf(hxc) = 2.^(iex-1023) + (imt ./ (2.^63)) ./ (2.^1011);
else
hxf(hxc) = (imt ./ (2.^63)) ./ (2.^1011);
end
hxf(hxc) = hxf(hxc) * isg;
end
else
error( ...
'BVQXtools:BadArgument',...
'Bad input class.' ...
);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -