diff vector2cell.m @ 14:a66aefd5e6ac

Added functions for converting vectors to and from cell format.
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Sep 2015 09:46:20 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vector2cell.m	Tue Sep 22 09:46:20 2015 +0200
@@ -0,0 +1,14 @@
+% Splits column vector v into segments of length n and returns the result as a column cell array.
+%   v  -- column vector to be split
+%   n  -- number of elements in each part
+%
+%   cv -- cell array of vectors with lenght n(i)
+function cv = vector2cell(v,n)
+    cv = cell(length(n),1);
+
+    ind = [0; cumsum(n)];
+    for i = 1:length(n)
+        ind_i = (ind(i)+1):ind(i+1);
+        cv{i} = v(ind_i);
+    end
+end
\ No newline at end of file