You can create a complete list of x,y pairs by expanding x to the size of y. Looking at your code, I think a single element of x belongs to a row of y, so:
xx = repmat(x(:), 1, size(y,2))
polyfit(xx, y, 1)
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!