%% ROI Table Mask from Categorical Sequence
% Generate a 16-sample categorical sequence mask with two categories, A and B. Specify as missing those samples that do not belong to A or B. Use the mask to create a signalMask object. Extract an ROI table mask from the object.

catSeq = categorical(["A" "A" "A" missing missing "B" "B" ...
  missing missing "B" "B" missing "B" "A" "A" "A"]);

m = signalMask(catSeq);

roiTbl = roimask(m)

%
% Output a list of categories and the number of regions belonging to each category.

[~,nroi,cats] = roimask(m)

%
% Merge same-category regions separated by only one sample.

m.MergeDistance = 1;

roiTbl = roimask(m)

% Copyright 2020 The MathWorks, Inc.