问题
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.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/20060515/matlab-subplot-for-2-rows-and-10-columns