You need to obtain all x values and their corresponding objective function values. Reference to the answer that the idea is taken from.
function cost = obj_function(x)
peristent X_Vals F_Vals
cost.X_Vals = X_Vals;
cost.F_Vals = F_Vals;
X_Vals(1,:) = [0 0];
F_Vals(1,1) = 0;
X_Vals(end+1,:) = x;
F_Vals(end+1,1) = cost;
After optimisation is finished call objective function without arguments, it will return a structure containing the needed values.
You'll get only points with the values, I am not sure if that is enough for the contour plot, if not, then check out scatteredInterpolant function.
Also, make sure you delete first row from both variables, since those are just values to initialise the variable. There's also another approach to run your optimisation nested, that way you can have variables in your workspace when optimisation is finished. You can find an example of it if you search the documentation or this website.