MATLAB: How to use the AXIS EQUAL functionality for a 3D plot in MATLAB 7.4 (R2007a)

MATLAB

I would like to be able to make an option in the ‘axis equal’ functionality to select 2 axes only and have the third axis scaled automatically. The following code shows that the ‘axis equal’ functionality doesn’t scale the figure properly:
figure
t = 0:pi/50:10*pi;
subplot(1,2,1); plot3(sin(t),cos(t),t);
title('Normal');
subplot(1,2,2); plot3(sin(t),cos(t),t);
axis equal;
title('Axis equal')

Best Answer

The ability to use the AXIS function for 3-D plots is not available in MATLAB.
To work around the issue, it is possible to scale all the three axes by using the 'DataAspectRatio' property of the axes object:
figure
t = 0:pi/50:10*pi;
subplot(1,2,1); plot3(sin(t),cos(t),t);
title('Normal');
subplot(1,2,2); plot3(sin(t),cos(t),t);
h = get(gca,'DataAspectRatio')
if h(3)==1
set(gca,'DataAspectRatio',[1 1 1/max(h(1:2))])
else
set(gca,'DataAspectRatio',[1 1 h(3)])
end
title('Axis equal')