You did not provide ‘x’ or any of the parameters (such as ‘Fs’) so it is not possible to run your code, and you could easily have posted your code as an attachment here instead of pastebin.
That aside, try this:
[pks,locs] = findpeaks(20*log10(abs(xdft));
figure(2)
semilogx(freq,20*log10(abs(xdft)))
hold on
plot(freq(locs), pks, 'or')
hold off
xlabel('f(Hz)');
title('FFT of signal')
It is necessary to use the same values in the plot as in the findpeaks arguments.
.
