Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: Subplot for 2 rows and 10 columns

How can I plot 20 images in one plot with 2 rows and 10 columns in matlab? I know I have to use

subplot()

function. But I am confused regarding the parameters to be given.

I tried giving

subplot(2,10,row_index,col_index)

but it doesn't seem to work.Please help.

like image 991
Doubting Avatar asked Mar 05 '26 23:03

Doubting


2 Answers

The first two arguments of the subplot function give the total number of rows and columns of subplots in the figure, respectively, and the third gives the row-wise linear index of the current subplot. If you want a 2x10 matrix of images, they will be numbered like this:

1 2
3 4
5 6
7 8
9 10

So, for instance, the second one over, third one down can be set using subplot(2,10,6).

You are not limited to putting a single image/axis on a single subplot. If you wanted to span an axis across the top two columns, you would use subplot(2,10,[1 2]) and the axis would stretch to fill both spots.

like image 156
craigim Avatar answered Mar 07 '26 19:03

craigim


It's very simple. The index is just into the total number of subplots.

figure
for i=1:20
   subplot(2,10,i);
   plot((1:10).^i)
end
like image 28
grantnz Avatar answered Mar 07 '26 21:03

grantnz