- double
- single
- int8
- uint8
- int16
- uint16
- int32
- uint32
- int64
- uint64
- logical
- char
if i execute its saying type input argument and run the code ? what input argument must type inside that ? please help me
조회 수: 1 (최근 30일)
이전 댓글 표시
% Entropy: Returns entropy (in bits) of each column of 'X'
% by Will Dwinnell
%
% H = Entropy(X)
%
% H = row vector of calculated entropies (in bits)
% X = data to be analyzed
%
% Example: Measure sample entropy of observations of variables with
% 1, 2, 3 and 4 bits of entropy.
%
% Note: Estimated entropy values are slightly less than true, due to
% finite sample size.
%
% X = ceil(repmat([2 4 8 16],[1e3,1]) .* rand(1e3,4));
% Entropy(X)
%
% Last modified: Nov-12-2006
function H = Entropy(X)
% Establish size of data
[n m] = size(X);
% Housekeeping
H = zeros(1,m);
for Column = 1:m,
% Assemble observed alphabet
Alphabet = unique(X(:,Column));
% Housekeeping
Frequency = zeros(size(Alphabet));
% Calculate sample frequencies
for symbol = 1:length(Alphabet)
Frequency(symbol) = sum(X(:,Column) == Alphabet(symbol));
end
% Calculate sample class probabilities
P = Frequency / sum(Frequency);
% Calculate entropy in bits
% Note: floating point underflow is never an issue since we are
% dealing only with the observed alphabet
H(Column) = -sum(P .* log2(P));
end
% God bless Claude Shannon.
% EOF
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 1월 26일
That routine should work if you pass it a column vector or 2D matrix, with any of the data types:
However, it would fail if you were to pass it a cell array or struct of any kind. (There is an easy modification that would permit it to work with cell arrays of string.)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!