compress.m

来自「脊波工具和相关实验以及有关实验数据」· M 代码 · 共 27 行

M
27
字号
function [c, err] = compress(a, ratio)
% COMPRESS Compress an array
%
%	[c, err] = compress(a, ratio)
%
% The "compression" is achieved by zero-out 100*ratio percent of array
% element with smallest magnitute (hence, ratio is between 0 and 1).

if (ratio < 0) | (ratio > 1)
    error('ratio must be between 0 and 1');
end

% Sort the coefficient in the order of energy.
asort = sort(abs(a(:)));
err = cumsum(asort.^2);
err = flipud(err);

% Threshold.
mind = floor(ratio * prod(size(a)));
if (mind > 0)
    thresh = asort(mind);
    c = a .* (abs(a) > thresh);
else
    c = a;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?