How can I set subplot size in MATLAB figure?

 I often need to plot 10 images together, but using this code results in small images : 

 

img = rand(400,600); 
for i=1:10
 subplot(2,5,i); 
 imshow(img); 
 title(['Image ' int2str(i)]); 
end

As you can see, the images do not use all available space in the screen. How can I increase the size, or decrease the padding/margin between them? 

Thanks for any help.  

NOTE:-


Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.    

Answers: 

I don't believe there is an easy way to do it. There are two options:

First, use the position part of the subplot: 

 

>> subplot(2,5, i, [l, b, w, h])

and calculate the left, bottom, width, height.

Or, get the handle of the returned axis: 

 

>> h(i) = subplot(2,5,i); 

nd then modify the axis afterward. 

 

>> set(h(1), 'position', [l, b, w, h] );

There are a number of pages that will give more detail, e.g., http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/

[update]

The code below gives a little more detail on who you can do something like what you are looking for. It is a tad tedious. The 0.95 and 0.02 are just to give a little padding. They are nothing magical. :-)

One other thing to note is I would really encourage you to use "ii" as your index variable (or something else) as "i" is defined as sqrt(-1). It is a good convention not to use "i" and "j" as index variables (especially in Matlab). 

 

img = rand(400,600); 

figure(1);
clf();
hold on;

% Get the width and height of the figure
lbwh = get(1, 'position');  
SEE COMPLETE ANSWER CLICK THE LINK    
https://matlabhelpers.com/questions/how-can-i-set-subplot-size-in-matlab-figure-.php

Comments

Popular posts from this blog

programmingshark

Why do I get a "Too many input arguments" error when not passing any?

Constructing piecewise symbolic function in Matlab