You can use the TEXTSCAN function by specifying delimiters and then use LENGTH function to find the length of each sequence. After that, you can compute the number of occurrences with HIST function as in the example below:
s = [1 1 0 0 0 0 0 1 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 1 1 1];
s = sprintf('%d',s);
t1=textscan(s,'%s','delimiter','1','multipleDelimsAsOne',1);
d = t1{:};
for k = 1:length(d)
data(k) = length(d{k});
end
[number_times run_length] = hist(data, [1:max(data)])
To do the same operation for finding run lengths and frequencies of "zeros" instead of "'ones", change the delimiter in the TEXTSCAN function to be '1' instead of '0'.
Best Answer