Shaded region inside plot

7 visualizaciones (últimos 30 días)
LIM MING HUI
LIM MING HUI el 30 de Abr. de 2022
Comentada: Voss el 30 de Abr. de 2022
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');

Respuesta aceptada

Voss
Voss el 30 de Abr. de 2022
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);
  2 comentarios
LIM MING HUI
LIM MING HUI el 30 de Abr. de 2022
Thanks for your help!
Voss
Voss el 30 de Abr. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by