I have a list of strings or arrays with different length or size. I want to use the shortest string and compare with other strings by shifting the shortest string window one by one to do comparison.
Let's say I want to do addition, I have [2 1 3]
as my shortest list and want to perform addition on [4 5 7 8 9]
1st addition: [2 1 3] + [4 5 7]
2nd addition: [2 1 3] + [5 7 8]
3rd addition: [2 1 3] + [7 8 9]
the example above for two arrays which i found can be solve with hankel
function.
a = [2 1 3];
b = [4 5 7 8 9];
idx = hankel(1:numel(a), numel(a):numel(b));
c = bsxfun(@plus, b(idx.'), a);
and the result:
c =
6 6 10 % [2 1 3] + [4 5 7]
7 8 11 % [2 1 3] + [5 7 8]
9 9 12 % [2 1 3] + [7 8 9]
but now, i want to perform for all of them and there are many combination. lets say arrays A
, B
, C
, D
, and E
, so the possible addition can be A+B
, A+C
, A+D
, A+E
, B+C
, B+D
, B+E
, C+D
, C+E
, D+E
.
for example:
A=[2 1 3];B=[4 5 7 8 9];C=[6 9];D=[3 6 4 2 1 1];E=[4 6 9]
for A+B
6 6 10
7 8 11
9 9 12
for A+C
8 10
7 12
for A+D
5 7 7
8 5 5
6 3 4
4 2 4
... and the rest
How can I do this using MATLAB? Many thanks