matlab:将十六进制值字符串转换为十进制值?

matlab:将十六进制值字符串转换为十进制值?,matlab,Matlab,我编写了将100000个十六进制字符串转换为值的函数,但在整个数组上执行需要10秒。Matlab是否有这样一个功能,使它更快。。。ie:阵列的时间不到1秒 函数x=hexchar2dec(c) 如果c>=48&&c=65&&c=97&&c尝试使用。它应该比在每个字符上循环快得多。尝试使用。它应该比在每个字符上循环快得多。答案显然是最好的。 但是,如果您想自己进行转换,您可能会发现以下方法很有用: 假设s是一个字符矩阵:所有十六进制数都具有相同的长度(如有必要,填充零),并且每行都有一个数字。

我编写了将100000个十六进制字符串转换为值的函数,但在整个数组上执行需要10秒。Matlab是否有这样一个功能,使它更快。。。ie:阵列的时间不到1秒



函数x=hexchar2dec(c) 如果c>=48&&c=65&&c=97&&c尝试使用。它应该比在每个字符上循环快得多。

尝试使用。它应该比在每个字符上循环快得多。

答案显然是最好的。
但是,如果您想自己进行转换,您可能会发现以下方法很有用:

假设
s
是一个字符矩阵:所有十六进制数都具有相同的长度(如有必要,填充零),并且每行都有一个数字。然后

ds = double( upper(s) ); % convert to double
sel = ds >= double('A'); % select A-F
ds( sel ) = ds( sel ) - double('A') + 10; % convert to 10 - 15
ds(~sel)  = ds(~sel) - double('0'); % convert 0-9
% do the sum through vector product
v = 16.^( (size(s,2)-1):-1:0 );
x = s * v(:); 
答案显然是最好的。
但是,如果您想自己进行转换,您可能会发现以下方法很有用:

假设
s
是一个字符矩阵:所有十六进制数都具有相同的长度(如有必要,填充零),并且每行都有一个数字。然后

ds = double( upper(s) ); % convert to double
sel = ds >= double('A'); % select A-F
ds( sel ) = ds( sel ) - double('A') + 10; % convert to 10 - 15
ds(~sel)  = ds(~sel) - double('0'); % convert 0-9
% do the sum through vector product
v = 16.^( (size(s,2)-1):-1:0 );
x = s * v(:); 
ds = double( upper(s) ); % convert to double
sel = ds >= double('A'); % select A-F
ds( sel ) = ds( sel ) - double('A') + 10; % convert to 10 - 15
ds(~sel)  = ds(~sel) - double('0'); % convert 0-9
% do the sum through vector product
v = 16.^( (size(s,2)-1):-1:0 );
x = s * v(:);