I am trying to organize a large array based on x,y coordinates. I want the result to be sorted (ascending) by y-coordinate, then within each y-coordinate sorted (ascending) by x-coordinate. (These are the coordinates of a bridge model). The data is stored in an excel sheet (linked: https://skydrive.live.com/?cid=a19c139fd96328c1&id=A19C139FD96328C1%21177&action=Share#cid=A19C139FD96328C1&id=A19C139FD96328C1%21109). Code shown below:
%get data
coord=xlsread('coord_data.xlsx','Sheet1', 'A2:C4207');%sort by y then x
coord_sort=sortrows(coord,[2,1]);%write back to sheet
xlswrite('coord_data.xlsx', coord_sort,'Sheet1','E2');
The result is that the y's are sorted properly, but within each y-coordinate, the x's are a bit out of order. (If you were to actually run the code with the given excel data, going from cell E34 to E35, there is a jump with those numbers appearing at cell E136 instead).
I've tried different configurations using sortrows (ie I sorted by x then y in two separate commands) the x-sorting went well in that case, but when I subsequently sorted by y, got the same result.
Why might these problems be occurring?
Thank you. Joe Riddle
Best Answer