How do I Plot images in two different figures
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
In this snippet below, I want subplot 1 and 2 as a part of the same figure, which is something I am to get. I need a separate plot figure of the "%Separate side figure". I am not able to obtain that. Can you please help me out here?
Also, if I comment pause(0.000000001), my plot doesn't show up. Do you guys know why?
Thanks!
for i = 1 : length(srcFilesKinect)
      axis off
      filenameBL = strcat( path,'sk_left_rgb/',srcFilesBL(i).name);
      I = imread(filenameBL); axis off
      subplot(3,2,1), subimage(I)                           % Subplot 1
      title( 'left')
      filenameBR = strcat( path,'sk_right_rgb/',srcFilesBR(i).name);
      I = imread(filenameBR);  axis off
      subplot(3,2,2), subimage(I)                           %Subplot 2
      title('right')
      filenameKinect = strcat( path2,srcFilesKinect(i).name);
      I = imread(filenameKinect);                           %Separate side figure
      %imshow(I);
      %subplot(3,2,3), subimage(I)
      image(I)
      title('Demo')
      fprintf('Reading %d th image\n',i)
      pause(0.000000001)
  end
댓글 수: 2
  Jan
      
      
 2017년 3월 14일
				Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging.
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
답변 (2개)
  Adam
      
      
 2017년 3월 14일
        doc figure
Just create a figure explicitly (which you should always do anyway unless you are plotting on a GUI you have created), get its axes explicitly and plot on them explicitly. e.g.
hFig = figure; hAxes = gca;
imshow( hAxes, I );
댓글 수: 2
  Adam
      
      
 2017년 3월 15일
				Ah, sorry, I didn't check and thought all plotting functions had this syntax now - I never use imshow myself. Apparently imshow is still archaic so you need to use
imshow( I, 'Parent', hAxes );
  Jan
      
      
 2017년 3월 14일
        
      편집: Jan
      
      
 2017년 3월 14일
  
      The pause is required to allow Matlab to update the graphics. The minimal delay is 0.01, so  pause(0.000000001) does the same as pause(0.01). I'd prefer drawnow for the updating, but both work reliably.
subimage is deprecated, prefer imshow.
Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging. I've renamed to to "path1".
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
Then:
Axes1H = subplot(3,2,1);
title('left');
Axes2H = subplot(3,2,2);
title('right');
Fig2H  = figure;
Axes3H = axes;
title('Demo');
for i = 1 : length(srcFilesKinect)
    filenameBL = fullfile(path1, 'sk_left_rgb', srcFilesBL(i).name);
    I = imread(filenameBL);
    imshow(I, 'Parent', Axes1H);
    axis off
      filenameBR = fullfile(path1, 'sk_right_rgb', srcFilesBR(i).name);
      I = imread(filenameBR);
      imshow(I, 'Parent', Axes2H)
      axis off
      filenameKinect = fullfile(path2, srcFilesKinect(i).name);
      I = imread(filenameKinect);
      imshow(I, 'Parent', Axes3H);
      axis off
      fprintf('Reading %d th image\n', i);
      drawnow;
  end
There will be better names than the counted "Axes1H", something more meaningful. Indices inside names of variables are a bad idea.
댓글 수: 2
  Jan
      
      
 2017년 3월 15일
				After
Fig2H  = figure;
Axes3H = axes;
Axes3H is a valid axes handle. It can only get invalid, if this axes is deleted, e.g. by clf or a similar command, or if its figure is deleted.
참고 항목
카테고리
				Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


