There's a bit of missing code here and some of it doesn't make quite sense, so I might be off on my solution. And, I'm going to assume that newsol is a structure and not an object. If so, trying making the following changes.
newsol.Position = Neighbor(pf_position);
newsol.Cost = ObjectiveFunction(newsol.Position);
position = Neighbor(pf_position);
cost = ObjectiveFunction(position);
newsol = struct('Position',position,'Cost',cost);