That suggests that your xpositions.mat does not have a variable named "xpositions".
Note:
[xpositions,ypositions] = meshgrid(xpositions,ypositions);
would overwrite xpositions and ypositions, which going to be a problem because you have it in a loop. Since your xpositions and ypositions do not change, meshgrid outside the loop and use the meshed variables inside the loop.