aboutsummaryrefslogtreecommitdiff
path: root/arrange_optics_along_x.m
diff options
context:
space:
mode:
Diffstat (limited to 'arrange_optics_along_x.m')
-rw-r--r--arrange_optics_along_x.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/arrange_optics_along_x.m b/arrange_optics_along_x.m
new file mode 100644
index 0000000..62db960
--- /dev/null
+++ b/arrange_optics_along_x.m
@@ -0,0 +1,19 @@
+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
+
+ [xs,indx]=sort(x);
+ cntr=1;
+ for i=indx
+ optics{cntr}=optics_unsorted{i};
+ cntr=cntr+1;
+ end
+end
+
+