I found a solution that worked after some trial and error! I sorted the 2d array based on the y-values first. Then I pulled out a subset of the array. this subset isolated one row of spots at a time. I then sorted this subset based on their x positions, and stored it back in the sorted_ref_centroids array. I iterated through every row and it worked great!
% Sort the entire coordinate array based on y-values
[sortedY, sortIndex] = sort(Y);
sortedX = X(sortIndex);
for i=0:N_r-1 %N_r is the number of rows of spots
% Now sort portions of the array. (y-values between 1-102,102-204, etc)
idx =i*N_c+1:(i+1)*N_c;%N_c is the number of columns of spots
%extract only part of the ref_centroids to sort
%now sort this subset based on x-values.
[sortedX, sortIndex] = sort(X);
sortedY = Y(sortIndex);
%put this reordered subset back into ref_centroids