Revision 495
(checked in by cbc, 12 years ago)
|
Initial import of Stark code.
|
Line | |
---|
1 |
function x = rldecode(len, val) |
---|
2 |
%RLDECODE Run-length decoding of run-length encode data. |
---|
3 |
% X = RLDECODE(LEN, VAL) returns a vector XLEN with the length of each run |
---|
4 |
% and a vector VAL with the corresponding values. LEN and VAL have the |
---|
5 |
% same lengths. X must be a vector. |
---|
6 |
% |
---|
7 |
% Example: rldecode([ 2 3 1 2 4 ], [ 6 4 5 8 7 ]) will return |
---|
8 |
% |
---|
9 |
% x = [ 6 6 4 4 4 5 8 8 7 7 7 7 ]; |
---|
10 |
% |
---|
11 |
% See also RLENCODE. |
---|
12 |
% |
---|
13 |
% Calls: none |
---|
14 |
|
---|
15 |
% Author: Peter J. Acklam |
---|
16 |
% Time-stamp: 2000-07-10 02:31:48 |
---|
17 |
% E-mail: jacklam@math.uio.no |
---|
18 |
% WWW URL: http://www.math.uio.no/~jacklam |
---|
19 |
|
---|
20 |
% keep only runs whose length is positive |
---|
21 |
k = len > 0; |
---|
22 |
len = len(k); |
---|
23 |
val = val(k); |
---|
24 |
|
---|
25 |
% now perform the actual run-length decoding |
---|
26 |
i = cumsum(len); % LENGTH(LEN) flops |
---|
27 |
j = zeros(1, i(end)); |
---|
28 |
j(i(1:end-1)+1) = 1; % LENGTH(LEN) flops |
---|
29 |
j(1) = 1; |
---|
30 |
x = val(cumsum(j)); % SUM(LEN) flops |
---|