Great, the first code snippet was exactly what I needed!
As for the 1-cdf(end) part, I'm not sure you are correct. The KS test searches for the
which is probably somewhere near the middle of the 0-0.5 or 0.5-1 ranges of cdf values.
In general, if my cdf is anything even close to gaussian it should have no problem to come very close to 1 at cdf(end), and I expect the 1-cdf(end) to always be (for a reasonable paramaters of GGD) very close to 0. Please, correct me if I'm wrong.
For the last advice on the topic (or a bit off topic), the

test needs distributions pdfs. I suppose it should be fine to use
Code:
[pdf,x]=ksdensity(Y);
to estimate the pdf of the values in Y?