Can you give a small example matrix and what you expect the output to be?
It is still not clear what you want. I asked you to provide input and output. You provided input, but no output. How would you group these, in a cell array?
Here is a guess:
A = [164
165
166
167
175
176
177
189
190
195
196];
T = [1;diff(A)]==1;
t1 = [1 findstr((T).',[0 1])];
t2 = [findstr((T).',[1 0]) length(T)];
H = cell(1,length(t1));
for ii = 1:length(t1)
H{ii} = A(t1(ii):t2(ii));
end
R = num2cell(A(~ismembc(A,cat(1,H{:}))));
H(end+1:end+length(R)) = R
.
.
EDIT
A one-liner (FWIW):
groups = mat2cell(A,diff([0;find(diff(A) ~= 1);length(A)]),1);
Best Answer