forked from anne-urai/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipvects.m
51 lines (39 loc) · 904 Bytes
/
zipvects.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function out = zipvects(in1, in2)
% 'zips' two vectors
% put in the same shape
in1 = in1(:);
in2 = in2(:);
n1 = length(in1);
n2 = length(in2);
% these have to be the same size
assert(isequal(n1, n2), 'inputs are not the same length');
% turn everything into cells
if iscell(in1) || iscell(in2),
if ~iscell(in1),
if isnumeric(in1),
in1 = num2cell(in1);
in1 = in1(:);
end
end
if ~iscell(in2),
if isnumeric(in2),
in2 = num2cell(in2);
in2 = in2(:);
end
end
% prepare the output
out = {};
for i = 1:n1,
out = cat(1, out, in1{i});
out = cat(1, out, in2{i});
end
end
if isnumeric(in1) && isnumeric(in2),
% prepare the output
out = [];
for i = 1:n1,
out = cat(1, out, in1(i));
out = cat(1, out, in2(i));
end
end
end