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])];

Leave a Comment