figure(1) r = 3; c = 3; fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'}; position = {}; outerposition = {}; for n = 1:(r*c) fprintf ('subplot (%d, %d, %d)\n', r, c, n) subplot (r, c, n) xlabel (sprintf ('xlabel #%d', n)) ylabel (sprintf ('ylabel #%d', n)) title (sprintf ('title #%d', n)) text (0.5, 0.5, sprintf('subplot(%d,%d,%d)', r, c, n), fmt{:}) axis ([0 1 0 1]) position{n} = get (gca, 'position'); outerposition{n} = get (gca, 'outerposition'); fprintf ('position = [%.4f, %.4f, %.4f, %.4f]\n', position{n}) fprintf ('outerposition = [%.4f, %.4f, %.4f, %.4f]\n', outerposition{n}) end fprintf ('subplot (%d, %d, 1:3)\n', r, c) subplot (r, c, 1:3) xlabel (sprintf ('xlabel #%d:%d', 1, 3)) ylabel (sprintf ('ylabel #%d:%d', 1, 3)) title (sprintf ('title #%d:%d', 1, 3)) text (0.5, 0.5, sprintf('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:}) axis ([0 1 0 1]) set (gca, 'color', 'none') position{end+1} = get (gca, 'position'); outerposition{end+1} = get (gca, 'outerposition'); fprintf ('position = [%.4f, %.4f, %.4f, %.4f]\n', position{end}) fprintf ('outerposition = [%.4f, %.4f, %.4f, %.4f]\n', outerposition{end}) axes hold on for n = 1:numel(position) p = position{n}; x1 = p(1) + [0, p(3), p(3), 0, 0]; y1 = p(2) + [0, 0, p(4), p(4), 0]; p = outerposition{n}; x2 = p(1) + [0, p(3), p(3), 0, 0]; y2 = p(2) + [0, 0, p(4), p(4), 0]; h = plot (x1, y1, '--b', x2, y2, '--r'); end set (h(1), 'color', [0 0.5 0]) set (h(2), 'color', 'm') axis ([0,1,0,1]) axis off set (gca, 'outerposition', [0 0 1 1], 'position', [0 0 1 1]) set (gca, 'color', 'none') v = ver; filename = strcat (lower (v(1).Name), '.eps'); print ("-depsc", "-loose", filename) system (sprintf ("epstopdf %s", filename)) delete (filename)