MATLAB: How can i write a loop for below function when n is only odd and from 1 till 50

%The function
clc; clear all;
c=4/pi;
w=2*pi;
dt=0.001;
tpts=(5/0.001)+1;
for n= 1:50
for m=1: tpts
S1(n,m)=(4/pi)*(1/(2*n-1))*sin((2*n-1)*w*dt*(m-1));
end
end
for m=1: tpts
S2=S1(:,m);
S3(m)=sum(S2);
end
f1=S3;
t=0.0:0.001:5 ;
plot(t,f1);
t=xlabel('time,[s]');
f1=ylabel('Amplitude,V');
grid;

Best Answer

n = 1:2:50;
(4./((2*n+1)*pi)).*sin((2*n+1)*pi*2*t)
provided that t is a scalar.