diff sortd.m @ 0:48b6fb693025

Initial commit.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Sep 2015 10:12:50 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sortd.m	Thu Sep 17 10:12:50 2015 +0200
@@ -0,0 +1,11 @@
+% Sorts x with respect to the function d
+% d is a function that accepts an element of x and returns a scalar.
+function y = sortd(d,x)
+    v = [];
+    for i = 1:length(x)
+        v(i) = d(x(i));
+    end
+
+    [~,I] = sort(v);
+    y = x(I);
+end
\ No newline at end of file