# matlab set center of output figure to [0 0 0]

I have a few set of data of three dimensional matrices, n x 3 with x, y and z coordinates. I viewed the matrices in the figure window.

% read function;
FV.vertices=OBJ1.vertices;
FV.faces=OBJ1.objects(2).data.vertices;
figure, patch(FV,'facecolor',[0 0 1]); camlight
grid on
axis equal


I want to read other sets of data by using the same function, but sets the center of each figure (not the center of origin) at [x y z]=[0 0 0].

Note that when I use the function above, the center of outputs is not always at [0 0 0].

Is it can be done by using translation function?

If you want a perfectly square set of axes with the center at $(0,0,0)$, while keeping all of the data on screen, I'd do something like this:

axis auto;
a = axis;
amax = max(abs(a));
axis([-amax,amax,-amax,amax,-amax,amax]);


If you like your axes limits to be integral, change max(abs(a)) to ceil(max(abs(a))).

• what if the center of 3D figure is not originally at [0 0 0]? for example: [x y z]=[29.24 -11.83 103]. can i really translate it to be [0 0 0]?
– user3991
Apr 26, 2013 at 3:05
• Well, you've gotta do what looks right. But the purpose of axis auto is to get the extends of the 3-D figure. I use those to determine the smallest cube, centered at the origin, that contains the extents of the figure. Apr 26, 2013 at 3:27