The lpad part is a little suspicious. If you have an odd length of signal it will not work as is.
Apart from that though:
The fft line simply runs the fft. Passing in the length of signal as the number of points is superfluous, but if you were using a different number of points (e.g. next power of 2, which is common) then that would be input there.
fft results in a 2-sided spectrum, with negative frequencies (or equiv nyquist to sample frequency) as well as positive frequencies (if you want to know more about this look for a resource online). Generally we aren't interested in the negative spectrum so we clip that off to give a one-sided spectrum.
fft returns its results as [0, positiveFrequencies, nyquist, negativeFrequencies]. We want to keep the nyquist frequency, hence n/2 + 1 rather than n/2.
scales the result to maintain the amplitudes of the time domain. I always forget exactly what this step should be, but I am assuming you have it right here. Certainly this is scaling the result, whether correctly or not.
xdft(2:end-1) = 2*xdft(2:end-1);
Because we threw away half the spectrum we multiply the remaining half by 2 to maintain the same total power.
In order to view the spectrum meaningfully you need to create your vector of frequencies. Obviously it needs to be the same length as the result and runs from 0 to Nyquist (which, if you remember is the range we kept from the spectrum).
The result of the fft is a complex one. To view the power spectrum you want the absolute value. Often this is also squared, but just taking the abs is also fine, depending what you wish to interpret from it.