# Fitting power law with loglog or exponential? [duplicate]

I have $$x$$- and $$y$$-data, and I want a power-law fit ($$y=ax^b$$). I always fit $$\log(x)$$ and $$\log(y)$$ by $$p_1x+p_2$$ (Matlab poly1), but when I fit $$x$$ and $$y$$ with $$p_1x^{p_2}$$, I did not get exactly the same result. Why?!

And what is the best way for doing this? First take logs then linear fit??