subplot( numRows, numColumns, index)

subplot( 2 , 3 , id )

subplot( 2 , 3 , 4 ) % index id=4 refers to first subplot in second line, see below

How to get subplot indexes for two loops over figure columns and rows?

Example 2 x 3 subplots, by using sub2ind

numRows = 2

numColumns = 3

for r=1:numRows

for c=1:numColumns

id = sub2ind([numColumns,numRows],c,r)

subplot(numRows, numColumns, id)

title(sprintf('Subplot %d',id))

xlabel(sprintf('Column %d',c))

ylabel(sprintf('Row %d',r))

% plot something ...



Note, while the subplot index goes horizontally (line by line), sub2ind refers to matrix-index which goes vertically (column by column). Thus, we need to switch column and row indexes.