Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight parts of matlab plot

I have a matlab plot that looks like this:

enter image description here

Where the Y values for each of the subplots are stored in single dimensional arrays. What i would like to do is to find an area where the top graph is above a certain height say 0.5. I would also like to highlight the same area in the other graphs as well.

Here is an example of what I am talking about:

enter image description here

The best i have been able to find so far is the function area which will fill an area on the matlab grid. However, if someone could tell me how to make it transparent and also how to fill multiple areas without having to do lots of area commands that would be great.

Otherwise I can identify a group of areas in a struct and use a for loop to plot them. Here is some psuedo code of the way i would do it:

countstruct = 1;
for i = 1:length(yValue)
    if (yValue(i) > 1)
        outside = [outside, i]
    else
         areas(countstruct).outside = outside;
         countstruct = countstruct + 1;
         clear outside;

     end
 end

Then to plot the areas i would do this:

for i = 1:length(areas)
    area(areas(i).outside, ones(length(area), 1)*14, "SomeThingToMakeItTransperant')
end

and i would do this for each of the subplots. Obviously this is quite convoluted so it would be better to have a one liner. Can anyone think of one?

like image 996
Fantastic Mr Fox Avatar asked Dec 05 '12 23:12

Fantastic Mr Fox


1 Answers

I figured it out, The psuedo code i provided gets the correct regions. You can then do this:

for i = 1:length(areas)
    harea = area(areas(i).outside, ones(length(areas(i).outside), 1)*14, 'LineStyle', 'none')
    set(harea, 'FaceColor', 'r')
    alpha(0.25)
    hold on
end

alpha sets the transparency in most area plots. This in combination with the code in the question results in this:

This is pretty cool to plot in matlab.

like image 61
Fantastic Mr Fox Avatar answered Oct 05 '22 10:10

Fantastic Mr Fox