0001 function blocks = dsIndexToBlocks(index)
0002
0003
0004 index_length = length(index);
0005 if any(index == 0)
0006 d_index = diff(index);
0007 starts = find(d_index == 1) + 1;
0008 stops = find(d_index == -1);
0009 else
0010 starts = 1;
0011 stops = index_length;
0012 end
0013
0014 if ~isempty(stops) || ~isempty(starts)
0015 if ~isempty(stops)
0016 if isempty(starts) || stops(1) < starts(1)
0017 starts = [1; starts];
0018 end
0019 end
0020 if ~isempty(starts)
0021 if isempty(stops) || starts(end) > stops(end)
0022 stops = [stops; index_length];
0023 end
0024 end
0025 stops(end) = min(stops(end), index_length);
0026 blocks = [starts stops];
0027 else
0028 blocks = [];
0029 end