在Matlab中将实数转换为基数2的所有可能方法中找到最小值?

在Matlab中将实数转换为基数2的所有可能方法中找到最小值?,matlab,Matlab,我正在使用此Matlab函数将基数10中的数字d转换为基数2,如前所述 例如dec2base_float(3/5,2,10)=0.1001100110 此函数提供了在base2中表示d的所有可能方法中的一种。在base2中表示d的所有可能方式中,是否有任何方式可以显示最小值?什么是“最小”方式?你到底在最小化什么?在所有以基数2表示d的方法中,最小值你已经说过了。显然,我不明白你的意思。我甚至不明白你所说的“所有可能的方式”是什么意思。你能给我们举一个例子,说明一些可能的方法,你想要哪一种方法吗

我正在使用此Matlab函数将基数
10
中的数字
d
转换为基数
2
,如前所述

例如
dec2base_float(3/5,2,10)=0.1001100110


此函数提供了在base
2
中表示
d
的所有可能方法中的一种。在base
2
中表示
d
的所有可能方式中,是否有任何方式可以显示最小值

什么是“最小”方式?你到底在最小化什么?在所有以基数2表示d的方法中,最小值你已经说过了。显然,我不明白你的意思。我甚至不明白你所说的“所有可能的方式”是什么意思。你能给我们举一个例子,说明一些可能的方法,你想要哪一种方法吗?例如,base 2中的1/2可以写成0.0111111。。。。或0.1000000。。。我想得到0.011111…因为它是两个值之间的最小值。0.011111不等于1/2。
function s = dec2base_float(d,b,nde)
%DEC2BASE_FLOAT Convert floating point numbers to base B string.
%   DEC2BASE_FLOAT(D,B) returns the representation of D as a string in
%   base B.  D must be a floating point array between 0 and 1.
%
%   DEC2BASE_FLOAT(D,B,N) produces a representation with at least N decimal digits.
%
%   Examples
%       dec2base_float(2/5,4,4) returns '0.1212'
%       dec2base_float(2/5,3,6) returns '0.101211'

%// Get "base power-ed scaled" digits
scale = b.^(-1:-1:-nde);

%// Calculate all possible combinations
P = dec2base(0:b^nde-1,b,nde)-'0';

%// Get the best possible combination ID. Index into P with it and thus get
%// based converted number with it
[~,idx] = min(abs(P*scale(:) - d));
s = ['0.',num2str(P(idx,:),'%0.f')];