MATLAB: Is there an efficient way to sort specific ranges/subsections of rows independently in a table by a particular column

sort tables

I want to sort sets of rows independently within a table e.g. a table such as
A 5
C 3
D 1
B 4
E 2
B 3
C 1
A 2
such that the first 5 rows and the last 3 rows are sorted separately in ascending order by column 2 so that the resulting table produced would be
D 1
E 2
C 3
B 4
A 5
C 1
A 2
B 3
Using nested loops is highly inefficient and I've been unsuccessful using sortrows(). Thanks for any suggestions.

Best Answer

splitapply() provided that you do not mind that disconnected regions with the same identifier code will be brought together