Run Length Encoding in Matlab

Here is a compact solution without loop, cellfun or arrayfun: chainCode=”11012321170701000700000700766666666666665555555544443344444333221322222322″; numCode = chainCode – ‘0’; % turn to numerical array J=find(diff([numCode(1)-1, numCode])); relMat=[numCode(J); diff([J, numel(numCode)+1])];

Repeat copies of array elements: Run-length decoding in MATLAB

Problem Statement We have an array of values, vals and runlengths, runlens: vals = [1,3,2,5] runlens = [2,2,1,3] We are needed to repeat each element in vals times each corresponding element in runlens. Thus, the final output would be: output = [1,1,3,3,2,5,5,5] Prospective Approach One of the fastest tools with MATLAB is cumsum and is … Read more