RunLength

버전 1.2.0.0 (18.7 KB) 작성자: Jan
RunLength coding as fast MEX and M-code
다운로드 수: 6.7K
업데이트 날짜: 2017/4/8

라이선스 보기

RUNLENGTH - Run-length coding
Run-length encoding splits a vector into one vector, which contains the
elements without neighboring repetitions, and a second vector, which
contains the number of repetitions.
This can reduce the memory for storing the data or allow to analyze sequences.
Encoding: [B, N, BI] = RunLength(X)
Decoding: X = RunLength(B, N)
INPUT / OUTPUT:
X: Full input signal, row or column vector.
Types: (U)INT8/16/32/64, SINGLE, DOUBLE, LOGICAL, CHAR.
B: Compressed data, neighboring elements with the same value are removed.
B and X have the same types.
N: Number of repetitions of the elements of B in X as DOUBLE or UINT8 row vector.
BI: Indices of elements in B in X as DOUBLE row vector.
RunLength(X, 'byte') replies N as UINT8 vector.

You can find a lot of RLE tools in the FileExchange already. This C-Mex is
about 5 times faster than good vectorized M-versions.
The M-file RunLength_M contains vectorized and loop M-code for education.

EXAMPLES:
Encode and decode:
[b, n] = RunLength([8, 9, 9, 10, 10, 10, 11])
x = RunLength(b, n)
% b = [8,9,10,11], n = [1,2,3,1], x = [8,9,9,10,10,10,11]
Limit counter to 255:
[b, n] = RunLength(ones(1, 257), 'byte')
% b = [1, 1], n = uint8([255, 2])
LOGICAL input:
[b, n] = RunLength([true(257, 1); false])
% b = [true; false], n = [257, 1]
Find the longest sequence:
x = floor(rand(1, 1e6) * 2);
[b, n, bi] = RunLength(x);
[longestRun, index] = max(n);
longestPos = bi(index);

The C-code is compiled automatically the first time RunLength is called.
See "RunLength_ReadMe.txt" for more details.

The unit-test uTest_RunLength tests validity and speed.

Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP/32, Win7/64
Compiler: LCC3.8, BCC5.5, OWC1.8, MSVC2008/2010
Does not compile under LCC2.4 shipped with Matlab/32!
Assumed Compatibility: higher Matlab versions, Linux, MacOS.

인용 양식

Jan (2024). RunLength (https://www.mathworks.com/matlabcentral/fileexchange/41813-runlength), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2011b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Large Files and Big Data에 대해 자세히 알아보기
도움

도움 준 파일: runindex, FillGaps_ez

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.2.0.0

2nd output is a column vector also, when the input is one. Thanks The Cyclist.

1.1.0.0

In the former submission the file RunLength.inc was missing. ReadMe added.

1.0.0.0