% Define the main region
x = 0:0.001:4;
y = exp(x) + sin(1./(x - 8.5));
% Define the sub region to enlarge
x1 = 0.4:0.001:0.6;
y1 = exp(x1) + sin(1./(x1 - 0.5));
% Main figure
figure;
plot(x, y);
grid on;
rectangle(‘Position’, [min(x1), min(y1), max(x1) - min(x1), max(y1) - min(y1)], ‘EdgeColor’, ‘r’); % mark the sub region
% Sub figure
sub = axes(‘Position’, [0.20, 0.25, 0.30, 0.25]); % location of the sub figure
plot(x1, y1);
xlim([min(x1), max(x1)]);
ylim([min(y1), max(y1)]);
set(sub, ‘XTick’, [], ‘YTick’, []);