MATLAB: How to split an array into smaller unequal-sized arrays dependend on array-column values

array

I have an array of 2 column and about 31,000 rows. One of the two columns depicts a spatial coordinate on a grid the other one a dependent parameter. What I want to do is the following:
I need to split the array into smaller parts defined by the spatial column; let's say the spatial coordinate are ranging from 0 to 500 – I now want arrays that give me the two column values for spatial coordinate 0-10, then 10-20 and so on. This would result in 50 arrays of unequal size that cover a spatial range from 0 to 500.
Thank you

Best Answer

Histcounts can be used to pin the data the way you want.
[~,~,BIN] = histcounts(mainArray(:,1), 0:10:500)
subArray1 = mainArray(bin==1,2);
subArray2 = mainArray(bin==2,2);
.
.
.
subArray50 = main array(bin==50,2)