MATLAB: Filling an area between max and minimum lines on a plot

fillMATLABplot

Hi,
I am trying to fill the area between the max at any given x and the min at any given x in the attached plot. I want it to be one colour.
This is the code that I am using to make the current plot:
low_thick = 0.0;
high_thick = 4.0;
incre_thick = 0.0001;
increments = low_thick:incre_thick:high_thick;
%%Plot figure and grab matrix
figure(); hold on
cmap = colormap(parula(71))
for idx = 5:14:71
month_data = data(:,idx);
total_n = sum(~isnan(month_data));
m = zeros(numel(increments),1);
for n = 1:numel(increments)
y = (sum(month_data < increments(n))/total_n)*100;
m(n,:) = y;
end
plot(m,increments,'color',cmap(idx,:))
clearvars month_data total_n
end
It is basically plotting how much of each series of data is under a threshold (y), and I want to have the area shaded and then the lines on top as well.
I've done a fair amount of searching and playing with fill() and area() with no luck.
Any assistance would be greatly received.
Thanks

Best Answer

See if Answer_332770 will give enough clues.
Basically, must build the lines of maxima/minima between the curves. That shouldn't be too bad if you've got the data as an array; I didn't try to read the code.
I didn't have time-enough to read the code to figure out the storage to save the data or the min/max while going through the loop, the easy way may be to "cheat" and just retrieve it from the plot when done...
hL(idx)=plot(plot(m,increments,'color',cmap(idx,:));
and then you can retrieve each after the plot is complete by
X=get(hL(1),'XData');
Y=cell2mat(get(hL,'YData'));
and then
Ymin=min(Y); YMax=max(Y);
ADDENDUM/ERRATUM
I forgot the linked-to Answer is an area plot because that poster wanted area to baseline; area can't do variable baseline; you need patch.
String the y min, max data out in long vector and call patch.
hA=patch([X fliplr(X)].',[YMin fliplr(yMax)].','r');
I did a real simple-minded simulation here to illustrate the idea--
subplot(2,1,1), hold on
for i=1:5,hL(i)=plot(rand(100,1));end % make a bunch of lines on the plot
X=get(hL(1),'XData'); % retrieve the x axis data (presume same)
Y=cell2mat(get(hL,'YData')); % and all the y data
yMn=min(Y); yMx=max(Y); % min, max of the y of all plot lines
subplot(2,1,2)
patch([X fliplr(X)].',[yMn fliplr(yMx)].','r')
results in
The second you can see is the bounded area of the first by visual comparison. NB: the reversal of the data for the second portion; patch needs an enclosed area so this draws minimum array from left to right; then sticks the RH end of the maximum array onto the end in reversed order to go back to the origin.
I did assume that the x- vector is the same for each line here; if that isn't so, you'll have to retrieve those positions that go with the min and max values by saving the indices in the optional second output argument of min,max and select the corresponding X.