2
votes

Hi all I have few problems in matlab :

Suppose I have 5 images and I want to plot all of them in a matlab figure window. How can I do so ? Meaning I want to put two images in the 1st row and 3 images in the 2nd row. I actually want this output.

enter image description here

OR something like this :

enter image description here

Please bear in mind that I want to center align the images in top row of both the figure windows. In short I want to know how I can specifically set the positions for my subplots within the matlab figure window ?

Also is there any way in which I can give a main title to my figure window ? I do not want to use the function SUPLABEL

The code I use is this :

h1=figure;
subplot(2,3,1);imshow(I_orignial);title('The original Image','FontWeight','bold','FontSize', 12);
subplot(2,2,2);imshow(aa1); title('1st segment','FontWeight','bold','FontSize', 12);
subplot(2,2,3);imshow(aa2); title('2nd segment','FontWeight','bold','FontSize', 12);
subplot(2,2,4);imshow(aa3); title('3rd segment','FontWeight','bold','FontSize', 12);

%//Please note that aa1,aa2 & aa3 are logical arrays and I_orignial is an uint8 image.
%//The size of the logical arrays is 64X64.
%//The size of the image is 160X221.

Also is there anyway in which I can resize my subplot images to a particular size before displaying on the figures ? I mean how can I force images of different sizes to the same subplot sizes on a matlab figure ? Please note : I am not talking about imresize.

For further clarification do get back to me!

Thanks in advance !!

2
Honestly what you're planning to do is quite complicated, maybe even impossible. You could try the subaxis package of the file exchange. But I highly recommend to you to save the time and do the image composition in illustrator or latex. Or is there a particular reason why you want to do this in matlab? - Robert Seifert
Thanks for replying. Actually I am not familiar with latex. And my code is written in matlab . The logical arrays are being generated in matlab command prompt. How can I transfer them to latex ? - roni
Well latex was just an example, you could use any other software as well. Obviously there is solution for matlab as well. - Robert Seifert

2 Answers

2
votes

If you want to use subplot, instead of directly specifying axes positions, you have to split, in your mind, the figure into the smallest uniform areas, and then combine them into plots. For example, to have three equal-sized plots, one on top and two on the bottom, you'd do:

firstAxes =  subplot(2,4,2:3);
secondAxes = subplot(2,4,5:6);
thirdAxes =  subplot(2,4,7:8);

If you want to perform more complex actions, such as putting text in a specific position, it's better to create display objects directly. For example:

   fh = figure;
   hiddenAxes = axes('parent',fh,'units','normalized','position',[0 0 1 1],'color','w','xcolor','w','ycolor','w','xlim',[0 1],'ylim',[0 1]);
   text('parent',hiddenAxes','position',[0.25 0.9 0.5 0.1],'horizontalAlignment','center','string','this is a centered title','fontWeight','bold')
   firstAxes =  axes('parent',fh,'units','normalized','position',[0.25 0.5 0.5 0.45]);
   secondAxes = axes('parent',fh,'units','normalized','position',[0 0 0.5 0.45]);
   thirdAxes =  axes('parent',fh,'units','normalized','position',[0.5 0 0.5 0.45]);

To control image size, you will want to change axes limits.

1
votes

You could also try

figure
subplot(2,3,1.5)
subplot(2,3,2.5)
subplot(2,3,4)
subplot(2,3,5)
subplot(2,3,6)

5plots_1-2centered or

subplot(2,2,1.5)
subplot(2,2,3)
subplot(2,2,4)

3plots_1centered