ksnf3000
ksnf3000

Reputation: 21

Entropy calculation in Matlab for uint32 type row vector

I need to calculate the entropy of a row vector.But the problem is my row vector is of uint32 type and Matlab gives an error that this type is not supported by the entropy() function.

I tried converting the uint32 to uint16 but this increased the size of the row vector and returned a result of 0!

Please let me know how should I go about this.

Thanks!

Upvotes: 1

Views: 792

Answers (2)

Nic
Nic

Reputation: 1310

If you convert the uint32 vector into a vector of double it should work

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 and ent_d should be the same

Upvotes: 1

gosnold
gosnold

Reputation: 181

If your vector is binary, you can compute the entropy H as follows (assuming vect is your original vector)

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

Source:http://en.wikipedia.org/wiki/Binary_entropy_function

Upvotes: 0

Related Questions