subplot function in matlab

subplot() function is used to plot 1 or more images on the same common MATLAB panel.

Syntax

subplot(<no of rows>,<no of columns>,<position of element from top left>), <image>;

Example

a = imread('Desert.jpg');
b = imread('desertg.jpg');
c = imread('images.jpg');
d = imread('penguins.jpg');
e = imread('Desertg.jpg');
f = imread('newImage.png');

% MATRIX CONTAINS 2 ROWS AND 3 COLUMNS
% 2x3 IS CONSTANT THROUGHOUT SUBPLOT, ONLY ELEMENT NUMBER CHANGES
subplot(2,3,1), imshow(a); % (first element of 2x3 matrix from top left)
subplot(2,3,2), imshow(b); % (second element of 2x3 matrix from top left)
subplot(2,3,3), imshow(c); % (third element of 2x3 matrix from top left)
subplot(2,3,4), imshow(d); % (fourth element of 2x3 matrix from top left)
subplot(2,3,5), imshow(e); % (fifth element of 2x3 matrix from top left)
subplot(2,3,6), imshow(f); % (sixth element of 2x3 matrix from top left)

Output

Share

You may also like...