rld.m
来自「matlab实现的游程编码的编码与解码过程」· M 代码 · 共 40 行
M
40 行
function [x] = rld(val,len)
% RLD Run Length Decoding
% X = RLD(VAL,LEN) decodes the run values, VAL, and run lengths, LEN, into
% vector X.
%
% Example:
% >> VAL = [1 3 8]
% >> LEN = [4 2 6]
% >> X = RLD(VAL,LEN)
% Returns:
% VAL =
% 1 3 8
% LEN =
% 4 2 6
% X =
% 1 1 1 1 3 3 8 8 8 8 8 8
%
% See also RLE.
% Steve Hoelzer
% 2003-09-04
% Error checking
if ~any(size(len)==1) | ~any(size(val)==1)
error('len and val must be vectors.')
end
if (length(len)~=length(val))
error('len and val vectors must be the same length.')
end
% Transpose len vector if necessary
if (size(len,2)==1)
len = len.';
end
% Decode
i = cumsum([ 1 len ]);
k = zeros(1, i(end)-1);
k(i(1:end-1)) = 1;
x = val(cumsum(k));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?