Skip to content

Instantly share code, notes, and snippets.

@chappjc
Created March 16, 2015 18:17
Show Gist options
  • Save chappjc/fc9047dae632da6fc65c to your computer and use it in GitHub Desktop.
Save chappjc/fc9047dae632da6fc65c to your computer and use it in GitHub Desktop.
function out = rld_cumsum_diff(vals,runlens)
% Divakar's solution to run-length-decoding
% (http://stackoverflow.com/a/29079288/2778484)
clens = cumsum(runlens);
idx(clens(end))=0;
idx([1 clens(1:end-1)+1]) = diff([0 vals]);
out = cumsum(idx);
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment