The result that you encounter when you are setting the 'XData', 'YData' and 'ZData' properties to itself is an expected behavior.
There are two different ways to set the coordinates of a Patch object. The first way is to use the Faces and Vertices properties which is what is used when the patch is created. The second way is to use the XData, YData, and ZData properties. These are actually parts of two separate user models.
The XData, YData, and ZData are convenience properties. If you set them, they get mapped to Faces and Vertices. It is not the case that all values of Faces and Vertices can be represented as XData, YData, and ZData. This means that if you set the Faces and Vertices properties, and then do something like the following:
set(ha,'XData',get(ha,'XData')+1)
you may get unexpected results. In this case, the XData, YData and ZData model it is impossible to represent shared vertices. This means that the result has to be flat shaded because the smoothing of the normals comes from averaging the facet normals at shared vertices.
This could be illustrated as follows:
size(get(ha,'vertices'))
ans =
1225 3
set(ha,'xdata',get(ha,'xdata'),'ydata',get(ha,'ydata'),'zdata',get(ha,'zdata'))
size(get(ha,'vertices'))
ans =
4816 3
Notice that there are suddenly 3 times as many vertices.
Since the patch in the code above was created using Faces and Vertices, it is preferred not to use the convenience properties.
For example, the following would work:
v=get(ha,'vertices');
v(:,1) = v(:,1)+1;
set(ha,'vertices',v);
Hence, to summarize if one creates a patch using the 'Vertices' and 'Faces' model then the 'XData', 'YData' or 'ZData' properties should not be used, and vice versa.
Best Answer