Let's look at the text of the error message.
Incorrect use of matlab.graphics.chart.primitive.Contour/setZDataImpl
Z must be at least a 2x2 matrix.
What are you using to set the Z data of the contour plot in your code?
set(h(k),'linewidth',2,'edgecolor','w', ...
'facealpha',.5,'zdata',4*k*ones(m(k),1))
What is the size of 4*k*ones(m(k), 1)? Does it have at least two rows and at least two columns? If m(k) is 2 or greater then it has at least two rows, but it's only going to have 1 column.
Rather than using length to create the value of m:
m(k) = length(get(h(k),'xdata'));
I think you'll want to use the size of the original Z data of the contour plot to create the new Z data for the contour plot instead.
Alternately, if I understand your description you might want to use either the contourslice function or (if you want to display a surface with the contour levels) maybe surfc.