0
votes

In MATLAB, I have the following sets of points:

T_arr =
        1000
         500
         400
         300
         200
         100

results =

    2.6000    
    2.2000    
    2.1500    
    2.1000    
    2.0000    
    1.8000 

When I plot them it looks like this:

plot(T_arr, results); hold on; 
plot(T_arr, results,'*'); 
xlabel('T'); 
ylabel('result'); 
title('T vs. result')

enter image description here

I would like to color the region above the curve in one color (say red) and the region below the curve in a different color (say blue). How can this be done in MATLAB?

I am aware there are two functions in MATLAB called fill and area , but I am unclear how to use them for this particular problem.

1

1 Answers

1
votes

To use fill we need to provide set of points that forms closed shape. We will use points from your data set and top left (x0,y0) and bottom right (x1, y1) corners of the picture.

enter image description here

Now we need to find these coords and call fill for two sets of points with different colors (last parameter in fill). You can avoid using max and min if data is sorted or limits are known. I plot areas before the line to make sure that markers will be visible - that is also the reason why I didn't used red and blue colors.

T_arr = [1000, 500, 400,300, 200, 100];
results =[2.6000,    2.2000,   2.1500,    2.1000,    2.0000, 1.8000 ];
plot(T_arr, results); hold on; 
x0 = min(T_arr);
y0 = max(results);
x1 = max(T_arr);
y1 = min(results);
fill([x0, T_arr],[y0, results],'g');
fill([x1, T_arr],[y1, results],'y');
plot(T_arr, results,'*'); 
xlabel('T'); 
ylabel('result'); 
title('T vs. result');

Here is the result:

enter image description here