Mercurial > repos > public > sbplib
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:b18d3d201a71 | 14:a66aefd5e6ac |
---|---|
1 % Splits column vector v into segments of length n and returns the result as a column cell array. | |
2 % v -- column vector to be split | |
3 % n -- number of elements in each part | |
4 % | |
5 % cv -- cell array of vectors with lenght n(i) | |
6 function cv = vector2cell(v,n) | |
7 cv = cell(length(n),1); | |
8 | |
9 ind = [0; cumsum(n)]; | |
10 for i = 1:length(n) | |
11 ind_i = (ind(i)+1):ind(i+1); | |
12 cv{i} = v(ind_i); | |
13 end | |
14 end |