[X,Y,Z] = peaks(50) ; % Create some dummy data. parallaxAngle = 0.5 ; % You can change this to suit yourself. cameraAnchor = [ max(X(:)) max(Y(:)) min(Z(:)) ] ; leftImage = figure; surf(X,Y,Z,'FaceColor',[0.8 0.8 0.8]) % Create the surface figure. axis vis3d ; % Lock the aspect ration for rotation. camtarget(gca,[cameraAnchor]) % Point the camera at the anchor point. view((-45 - parallaxAngle),30) ; % Rotate the figre to the correct angle. title ('Plot Title', 'FontWeight','Bold','FontSize',11) % Add labels... xlabel ('X Axis Label', 'FontWeight','Bold','FontSize',11) ylabel ('Y Axis Label', 'FontWeight','Bold','FontSize',11) zlabel ('Z Axis Label', 'FontWeight','Bold','FontSize',11) grid on ; % Switch on the figure grid, and set(gca,'GridLineStyle','-') % set the grid to solid lines. rightImage = figure; surf(X,Y,Z,'FaceColor',[0.8 0.8 0.8]) % Create the surface figure. axis vis3d ; % Lock the aspect ration for rotation. camtarget(gca,[cameraAnchor]) % Point the camera at the anchor point. view((-45 + parallaxAngle),30) ; % Rotate the figre to the correct angle. title ('Plot Title', 'FontWeight','Bold','FontSize',11) % Add labels... xlabel ('X Axis Label', 'FontWeight','Bold','FontSize',11) ylabel ('Y Axis Label', 'FontWeight','Bold','FontSize',11) zlabel ('Z Axis Label', 'FontWeight','Bold','FontSize',11) grid on ; % Switch on the figure grid, and set(gca,'GridLineStyle','-') % set the grid to solid lines. print(leftImage ,'-dtiffn','-painters', 'Left_Eye.tif') print(rightImage,'-dtiffn','-painters','Right_Eye.tif') leftEyeImage = imread('Left_Eye.tif') ; % Load the left eye image. rightEyeImage = imread('Right_Eye.tif') ; % Load the right eye image. leftEyeImage(:,:,2:3) = 0 ; % Removes green and blue from the left eye image. rightEyeImage(:,:,1) = 0 ; % Removes red from the right eye image. anaglyph = leftEyeImage + rightEyeImage ; % Combines the two to produce the finished anaglyph. imshow(anaglyph,'border','tight') ; % Show the anaglyph image with no padding. print(gcf,'-dtiffn','-painters','Anaglyph.tif') % Save the anaglyph image.