bin2num.m
来自「Two functions, num2bin and bin2num are p」· M 代码 · 共 39 行
M
39 行
function z = bin2num(s);%z = bin2num(s)%Purpose: Convert a string representation of a%double. It is the inverse operation of num2bin% >x = pi;% >s = num2bin(x)% s =% % +.11001001000011111101101010100010001000010110100011000*2^+2% >z = bin2num(s)% z =% % 3.14159265358979% >z==x% ans =% 1%% H. Gollwitzer, 09/09/99% Modified to handle several rows, 11/12/00 HEG%Few checks on input string.n = size(s,1);z = zeros(n,1);for k = 1:n pspot = findstr(s(k,:),'.'); hatspot = findstr('^', s(k,:)); if isempty(pspot) | isempty(hatspot) error(sprintf('Check line %i i input string\n',k)) else man = '1' == s(k,pspot+((hatspot-3):-1:1)); F = polyval([man,0],1/2);%exact value of fractional part if s(k,1) == '-' F = -F; end E = str2num(s(k,(1+hatspot):end));%Value of exponent z(k) = pow2(F,E);%rescale by power of 2 endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?