MATLAB: Subtracting different sized arrays in intervals

arrayelementwisesubtractionwithout loop.

Hello everyone,
i have a problem where i just cant wrap my head around: I have two arrays, one is a 2678400×1 double (call this A) and one is a 4464×1 double (call this B). I want to subtract the first element of B from the first 600 elements of A, then the second element of B from the 601 to 1200 elements of A without using a loop. The calculated array would look something like this:
C(1) = A(1) – B(1)
C(2) = A(2) – B(1)
C(3) = A(3) – B(1)
C(601) = A(601) – B(2)
C(1201) = A(1201) – B(3)
etc.
I am using MatLab R2015a

Best Answer

A=(1:24)';
B=(1:6)';
C=A-repelem(B,numel(A)/numel(B))