you can try also this simple option:
x = 0:.01:4*pi; %// x data
y = sin(x); %// y data
level = 0.5; %// level
lineStart = find(y>=level,1);
lineEnd = find(y(lineStart:end)<=level,1)+lineStart;
plot(x,y)
hold all
area(x(lineStart:lineEnd),y(lineStart:lineEnd),...
level,'EdgeColor', 'none', 'FaceColor', [.7 .7 .7],'ShowBaseLine','off')
line([x(lineStart),x(lineEnd)],[level level ])
hold off
without defining areas of interest a-priory:
And don't forget to hold off
...
To calaulate the area:
A = trapz(x(lineStart:lineEnd),y(lineStart:lineEnd))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…