|
你可以试试换个思路,先把f(x)下区域全部涂蓝,再把y = 1下区域全部涂绿,最后把f(x)与y = 1下的交集涂白
1 N8 W7 D P2 N) e! C, Px = 0:1:20;
5 d% P) a. z. R( r+ Fy = 2*rand(1,21);
3 B( f5 m, i, ~6 _6 S4 cxi = 0:1e-2:20;
% o6 x. u5 |: ]yi = interp1(x,y,xi,'linear');, N, Y7 [% B% u2 w
close all;hold on
' t+ E+ ^; p: k8 D* b) W8 [area(xi(yi>1),yi(yi>1),'FaceColor','b'): K- f* S$ W' M& D3 n; Q, y
area(xi(yi<1),0.*xi(yi<1)+1,'FaceColor','g')8 C6 o. T6 Z- {! X ~' B
area(xi,bsxfun(@min, yi, 1),'FaceColor','w')' ]! X) c2 K% j
plot(xi,yi,'k-','LineWidth',2) |
|