How to shade an area bound by 2 curves in an ezplot?
3 次查看(过去 30 天)
显示 更早的评论
I have a plot depicting two symbolic functions:
syms x
y1 = 0.05*x;
y2 = log10(x);
figure
ezplot(y1)
hold on
ezplot(y2)
hold off
I need to shade two bounded regions: the area below y1 and to the left of y2, and the area above y1 and to the right of y2. I tried to use the `fill' function, but I don't think that works for symbolic math functions in ezplot. Any help will be appreciated.
0 个评论
采纳的回答
Christopher Creutzig
2014-3-31
You can get the x and y data from a plot and then use fill or patch, although it is not necessarily straightforward and you need to find the intersection point:
syms x
f1 = 0.05*x;
f2 = log10(x);
x0 = double(solve(f1 == f2)); % and manually check it is a single value in the range we want
figure
h1 = ezplot(f1);
hold on
h2 = ezplot(f2);
xd1 = get(h1, 'XData'); xd2 = get(h2, 'XData');
yd1 = get(h1, 'YData'); yd2 = get(h2, 'YData');
% limit to finite values
yd2 = max(yd2, -5);
% revert one line, since we need to “circle” around the areas to fill
xd2 = xd2(end:-1:1);
yd2 = yd2(end:-1:1);
fill([xd1(xd1 < x0) xd2(xd2 < x0)], [yd1(xd1 < x0) yd2(xd2 < x0)], 'b');
fill([xd1(xd1 > x0) xd2(xd2 > x0)], [yd1(xd1 > x0) yd2(xd2 > x0)], 'r');
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!