MATLAB: Can you help me to plot the derivative of the function.

can you help me to plot the derivative of the function.

I have a code matlab:
k = 3;
N = 2500;
L = 250;
B = L/N ;
dn = 1/L;
n0 = 0.1;
n = dn : dn : N*dn;
phi = 2*pi*rand(size(n));
Amp1 = sqrt(dn)*(2^k)*(1e-3)*(n0./n);
x = 0:B:L-B;
hx = zeros(size(x));
for i=1:length(x)
hx(i) = sum(Amp1.*cos(2*pi*n*x(i)+ phi));
end
Can you help me to plot the derivative of the function hx(i).
Thank you so much. Have a good day.

Best Answer

plot(diff(hx));
https://in.mathworks.com/help/matlab/ref/diff.html