You have coded the essential loop correctly. The problem is that you overloaded your code with a lot of irrelevant items. I would increase the resolution of ‘t’, and simply use the ‘k’ loop:
t = linspace(0,4*pi);
n = 100;
me = zeros(n+1, numel(t));
for k = 0:n
me(k+1,:) = ((-1).^k)*sin(2.*k.*t+t)./(2.*k+1).^2;
end
me = sum(me);
figure
plot(t, me)
The plot is not necessary for the code. It simply shows the result.
Experiment to get the result you want.