我编写了将 100,000 个十六进制字符串转换为值的函数,但在整个数组上执行需要 10 秒。Matlab 是否具有执行此操作的功能,以便它更快,...即:数组少于 1 秒?
function x = hexstring2dec(s)
[m n] = size(s);
x = zeros(1, m);
for i = 1 : m
for j = n : -1 : 1
x(i) = x(i) + hexchar2dec(s(i, j)) * 16 ^ (n - j);
end
end
function x = hexchar2dec(c)
if c >= 48 && c <= 57
x = c - 48;
elseif c >= 65 && c <= 70
x = c - 55;
elseif c >= 97 && c <= 102
x = c - 87;
end