MATLAB: Finding the first and the last elements of consecutive numbers and combining them with a semi colon.

array

Hello,
I need to make an array of the first and the last number of a consecutive numbers and combine them with a delimator(;).
I need this format of an array ;
answer = [1 5; 10; 20 23]
When given this kind of input;
outliers = [1 2 3 4 5 10 20 21 22 23];
This is my code so far, but I have no idea how to combine the result into one array…
Could you please help me?
Thank you.
outliers = [1 2 3 4 5 10 20 21 22 23];
grouped = mat2cell( outliers, 1, diff( [0, find(diff(outliers) ~= 1), length(outliers)] )) ;
for group_idx = 1:length(grouped)
first = [cellfun(@(x)x(1),grouped)];
last = [cellfun(@(x)x(end),grouped)];
format = sprintf(['%.0f ' '%.0f;'], [first(group_idx) last(group_idx)])
end

Best Answer

ii = cumsum([true,diff(outliers)~=1]);
A = accumarray(ii(:),outliers(:),[],@(x){[min(x),max(x)]});
out = reshape([A{:}],2,[])';