To use fill (and its related functions), you need to outline the first curve, then flip the second curve, providing a ‘closed path’ (that the function itself will then complete if necessary) to outline them correctly. Since your vectors are all column vectors here, you need to vertically concatenate the first vectors and their flipped second vectors.
Try this:
y=[0,1;2,2;2,3;3,5];
xlimit=y(:,1);
ylimit=y(:,2);
x=[0,5;1,5;2,5;3,5];
boundryxlim=x(:,1);
boundryylim=x(:,2);
figure
fill([xlimit; flipud(boundryxlim)], [ylimit; flipud(boundryylim)], 'g')
hold on
plot(xlimit,ylimit, 'b' )
plot(boundryxlim,boundryylim, 'r')
hold off
Best Answer