MATLAB: Is there a way I can merge figure two and figure three in the same figure? Trying to make a 3D movie and having the two figures in one would reduce developing time and editing.

3d imagesstereostereopair

%%create stereopair from matlab binary file
load F0001_NE00WH_PROC.mat
options.face_vertex_color = pointColors./255;
plot_mesh(points,faces,options); lighting phong
hold
plot3(fpoints_xyz(:,1),fpoints_xyz(:,2),fpoints_xyz(:,3),'*');
% fpoints_xyz = fiducial points on face
% faces = triangulation mesh information for 3D surface
% points = vertex x y z location for 3D surface
% fpoints_xyz(39,:) is the location of tip of nose.
% the below translating the object in the virtual space where its tip of
% nose locate at (0 0 255)
points(:,1) = points(:,1) - fpoints_xyz(39,1);
points(:,2) = points(:,2) - fpoints_xyz(39,2);
points(:,3) = points(:,3) - fpoints_xyz(39,3)+ 255;
hfig1 = figure('Position',[100 100 401 601],'color',[0 0 0]);
axes('ytick',[],'xtick',[],'yticklabel',[],'xticklabel',[],'color',[0 0 0],'position',[0 0 1 1],'Xlim',[-100 100],'ylim',[-150 150]);
%h = patch('Vertices', points, 'faces', faces,'FaceVertexCData', pointColors./255,'FaceColor','interp','EdgeColor','none');
options.face_vertex_color = pointColors./255;
plot_mesh(points,faces,options); material dull; lighting none;
% this method uses a virtual camera to capture an image of an object in virtual space
% Here virtual camera is human eye. The camera take a picture at the
% location of left eye and take another one at the location of right eye
% below is the calculation to create a stereopair.
% you can change the tc and D to simulate appropriate scenarios for your
% application.
tc = 63.36;%63.36; %32.9; % 63.36 mm interocular distance
D = 500;%22; % 500 mm = 50 cm . Distance from the object to the camera.
VA = 4*atand(400/2/D)+2; % check the equation for VA, by changing this you can change the size of object in the image
set(gca,'projection','orthographic');
set(gca,'cameraposition',[tc/2, 0, 255+D])
set(gca,'cameratarget',[0 0 255])
set(gca,'cameraupvector',[0 1 0]);
set(gca,'cameraviewangle',VA);
drawnow;
pause(1);
T = getframe(hfig1);
Rimage = T.cdata;
hfig2 = figure('Position',[100+401 100 401 601],'color',[0 0 0]);
axes('ytick',[],'xtick',[],'yticklabel',[],'xticklabel',[],'color',[0 0 0],'position',[0 0 1 1],'Xlim',[-100 100],'ylim',[-150 150]);
plot_mesh(points,faces,options); material dull; lighting none;
set(gca,'projection','orthographic');
set(gca,'cameraposition',[-tc/2, 0, 255+D]);
set(gca,'cameratarget',[0 0 255])
set(gca,'cameraupvector',[0 1 0]);
set(gca,'cameraviewangle',VA);
drawnow;
pause(1);
T = getframe(hfig2);
Limage = T.cdata;
hdig = figure;
subplot(1,2,1); imshow(Limage);
subplot(1,2,2); imshow(Rimage);
% imwrite(Limage,'Disfigured_Target_L.tif','tif');
% imwrite(Rimage,'Disfigured_Target_R.tif','tif');
pause(1);
% close(hdig); close(hfig1); close(hfig2);

Best Answer

Something like,
hfig = figure('Position',[100 100 401+401 601],'color',[0 0 0]);
hfig1 = axes('ytick', [], 'xtick', [], 'yticklabel', [], 'xticklabel', [], 'color', [0 0 0], 'Units', 'pixel', 'position',[0 0 401 601], 'Xlim', [-100 100], 'ylim', [-150 150]);
Yes, I know that hfig1 suggests a figure but you are storing an axes in it. That saves you from changing the line
T = getframe(hfig1);
Then later
hfig2 = axes('ytick', [], 'xtick', [], 'yticklabel', [], 'xticklabel', [], 'color', [0 0 0], 'Units', 'pixel', 'position', [402 0 401 601], 'Xlim', [-100 100], 'ylim', [-150 150]);
Again with the strange naming to avoid changing the line
T = getframe(hfig2);
I would use a name that reflected an axes, but that's me...
If you are creating a movie then you should set these up first and then update their contents within the loop. Your current code creates one new figure for every iteration, because of the
hdig = figure;
near the bottom of it.