To plot the surface only within the specified bounds, you need to mask the values outside the bounds. This can be achieved by setting the Z values to NaN where the points fall outside the desired region. Here's how you can do it:
- Define the bounds as logical conditions.
- Apply these bounds to mask out the unwanted parts of the surface.
ymin1 = @(x) 0.25 * x.^2;
yTop2 = ones(1, length(x2));
fun = @(x, y) sin(4 .* x) + y.^2 + 2;
[X, Y] = meshgrid(0:0.05:2, 0:0.05:1);
if (x >= xmin1 && x <= xmax1 && y >= ymin1(x) && y <= ymax1(x)) || ...
(x > xmax1 && x <= xmax2 && y >= ymin1(x) && y <= 1)
fill([x1 x2 xAll], [yTop1 yTop2 yBot], 'b');
- The "mask" array is created to identify the points within the specified bounds.
- The Z values outside the bounds are set to "NaN" to mask them.