aboutsummaryrefslogtreecommitdiff
path: root/arrange_optics_along_x.m
blob: 817656a86af8f1e6790d700612c88cb2b3f7547c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function optics = arrange_optics_along_x(optics_unsorted)
% arrange optics in proper order so its x position increases with consequent index
	N=length(optics_unsorted);

	% assign x positions
	x=zeros(1,N);
	for i=1:N
		x(i)=optics_unsorted{i}.x;
    end

    if issorted(x)
        optics = optics_unsorted;
        return
    end
    
    [xs,indx]=sort(x);
	cntr=1;
	for i=indx
		optics{cntr}=optics_unsorted{i};
		cntr=cntr+1;
	end
end