【问题标题】:Entropy calculation in Matlab for uint32 type row vectorMatlab中uint32类型行向量的熵计算
【发布时间】:2014-09-02 00:31:44
【问题描述】:

我需要计算行向量的熵。但问题是我的行向量是 uint32 类型,Matlab 给出的错误是 entropy() 函数不支持这种类型。

我尝试将 uint32 转换为 uint16,但这增加了行向量的大小并返回 0!

请让我知道我该怎么做。

谢谢!

【问题讨论】:

  • 没有相同的结果。矩阵大小只会增加。我想指出的一件事是这个行向量只包含 0 或 1 的值。

标签: matlab entropy uint32


【解决方案1】:

如果你的向量是二进制的,你可以计算熵 H 如下(假设 vect 是你的原始向量)

p=sum(vect==1)/length(vect); %the probability of having a 1 in your vector
H=-p*log2(p)-(1-p)*log2(1-p);

来源:http://en.wikipedia.org/wiki/Binary_entropy_function

【讨论】:

  • 下标索引必须是正整数或逻辑数。
【解决方案2】:

如果您将 uint32 向量转换为双精度向量,它应该可以工作

a = randi([0 1],1,100); % original vector

b = uint32(a); % convert a into a uint32 vector
b = uint16(b); % make b a uint16 vector
d = double(b); % convert b into double vector

ent_a = entropy(a)
ent_b = entropy(b)
ent_d = entropy(d)

ent_a 和 ent_d 应该是一样的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2018-07-09
    • 1970-01-01
    • 2015-01-31
    相关资源
    最近更新 更多