我在数组中有各个位,我将它们传递给arithenco(seq,counts)函数。
seq = int8(seq);
p1 = 100*(sum(seq)/length(seq));
counts = [p1 1];
code = arithenco(seq, counts);
在错误检查中一直失败:
% Check to make sure that finite positive integer values (non-complex) are
% entered for SEQ
if ~all(seq > 0) || ~all(isfinite(seq)) || ~isequal(seq, round(seq)) || ...
~isreal(seq)
error(message('comm:arithenco:InvalidSymbolSequenceParameter1'));
return;
end
我最初传入一个双数组,所以我用seq = uint8(seq);
和
seq = int8(seq)
但我仍然收到此错误!
我是Matlab的新手,我确信这是一个简单的修复方法,但无论我尝试什么都不能修复它。
arithenco()文档声明:
code = arithenco(seq,counts) generates the binary arithmetic code corresponding to the sequence of symbols specified in the vector seq. The vector counts represents the source's statistics by listing the number of times each symbol of the source's alphabet occurs in a test data set.
This example illustrates the compression that arithmetic coding can accomplish in some situations. A source has a two-symbol alphabet and produces a test data set in which 99% of the symbols are 1s. Encoding 1000 symbols from this source produces a code vector having many fewer than 1000 elements. The actual number of elements in code varies, depending on the particular random sequence contained in seq.
counts = [99 1]; % A one occurs 99% of the time.
len = 1000;
seq = randsrc(1,len,[1 2; .99 .01]); % Random sequence
code = arithenco(seq,counts);
s = size(code) % length of code is only 8.3% of length of seq.
The output is
s = 1 83
答案 0 :(得分:0)
问题在于序列中的位,或者生成计数数组的方式。以下工作正常:
len = 1000;
seq = randsrc(1,len,[1 2; .99 .01]);
counts = [99 1];
code = arithenco(seq, counts);
我认为你的问题可能就在这里:
p1 = 100*(sum(seq)/length(seq));
您的p1必须是整数。
如果您认为您的序列是正确的,您可以尝试以下内容:
p1 = floor(100*(sum(seq)/length(seq)));