MATLAB: Product of a series

multiplicationprod

Hi,
how should I write this production in matlab?
p(k)=(m1−m2)*(m2−m3)*,…*,(mN−2−mN−1)*(m99−m100), where k from 1 to 100.
thx

Best Answer

Numerically:
m = rand(1, 100);
m = rand(1, 100); % Row Vector
rm = reshape(m, 2, []);
p = prod(diff(rm,[],1)) % Desired Result

EDIT — (21 Dec 2019 at 15:46)
Alternatively:
p = prod(-diff(rm,[],1)) % Desired Result
in the event that the first row was supposed to be subtracted from the second, instead of the second being subtracted from the first.