Shaded region inside plot

8 次查看(过去 30 天)
LIM MING HUI
LIM MING HUI 2022-4-30
评论: Voss 2022-4-30
Hello, I want to ask is it possible to shade thses 4 region with different colour?
x=[0:0.001:20];
y=(1/(2*0.2*9.81))*x.^2;
z=x*(10*3.7/(((3)^(1/2))*0.2*9.81))^(1/2);
plot(x,y,'m-', 'LineWidth', 3);
hold on;
plot(x,z,'k-', 'LineWidth', 3);
hold on;
x2 = [x,fliplr(x)];
y2 = [y,fliplr(z)];
fill(x2,y2,'b','LineStyle','none');

采纳的回答

Voss
Voss 2022-4-30
x=[0:0.001:20];
y=(1/(2*0.2*9.81))*x.^2;
z=x*(10*3.7/(((3)^(1/2))*0.2*9.81))^(1/2);
colors = [ ...
1 1 0; ... % 1: yellow
0 1 0; ... % 2: green
0 1 1; ... % 3: cyan
0.5 0.5 0.5]; % 4: grey
idx = find(y > z,1);
fill( ...
[x x(end) x(1)], ...
[z(1:idx) y(idx+1:end) 120 120], ...
colors(1,:),'LineStyle','none');
hold on
fill( ...
[x(1:idx-1) x(idx-1:-1:1)], ...
[z(1:idx-1) y(idx-1:-1:1)], ...
colors(2,:),'LineStyle','none');
fill( ...
[x(idx:end) x(end:-1:idx)], ...
[y(idx:end) z(end:-1:idx)], ...
colors(3,:),'LineStyle','none');
fill( ...
[x x(end) x(1)], ...
[y(1:idx) z(idx+1:end) 0 0], ...
colors(4,:),'LineStyle','none');
% plot the y and z lines last so they aren't obscured by the fills
plot(x,y,'m-', 'LineWidth', 3);
plot(x,z,'k-', 'LineWidth', 3);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by