Skip to content

Instantly share code, notes, and snippets.

@chappjc
Created March 16, 2015 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chappjc/7db48721c09c29f607e9 to your computer and use it in GitHub Desktop.
Save chappjc/7db48721c09c29f607e9 to your computer and use it in GitHub Desktop.
function V = knedlsepp5cumsumaccumarray(values, runLengths)
% knedlsepp's solution to run-length-decoding originally from http://stackoverflow.com/a/28615814/2778484
% (results in http://stackoverflow.com/a/29079288/2778484)
%// Actual computation using column vectors
V = cumsum(accumarray(cumsum([1; runLengths(:)]), 1));
V = V(1:end-1);
V = reshape(values(V),[],1);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment