How do I shade area in between two functions?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I made a plot to show stability conditions for these two conditions, but I want to shade the region in the graph. How do I do this?
kp = -10:0.1:10;
ki = zeros(size(kp));
for iter = 1:length(kp)
ki(iter) = 221*kp(iter) + 1326
end
figure(1)
clf
hold on
plot(kp, zeros(size(ki)), 'b.')
plot(kp, ki, 'r.')
axis tight
xlabel('Gain k_p')
ylabel('Gain k_i')
title('Stability Bounds, k_i vs. k_p')
grid
0 comentarios
Respuesta aceptada
Voss
el 23 de Mzo. de 2024
Editada: Voss
el 23 de Mzo. de 2024
kp = -10:0.1:10;
% ki = zeros(size(kp));
% for iter = 1:length(kp)
% ki(iter) = 221*kp(iter) + 1326
% end
ki = 221*kp + 1326;
figure(1)
% clf
idx = ki >= 0;
xf = [kp(idx) flip(kp(idx))];
yf = [ki(idx) zeros(1,nnz(idx))];
fill(xf,yf,'g','EdgeColor','none')
hold on
plot(kp, zeros(size(ki)), 'b.')
plot(kp, ki, 'r.')
axis tight
xlabel('Gain k_p')
ylabel('Gain k_i')
title('Stability Bounds, k_i vs. k_p')
grid
1 comentario
Voss
el 23 de Mzo. de 2024
Editada: Voss
el 23 de Mzo. de 2024
kp = -10:0.1:10;
% ki = zeros(size(kp));
% for iter = 1:length(kp)
% ki(iter) = 221*kp(iter) + 1326
% end
ki = 221*kp + 1326;
figure(1)
% clf
idx = ki <= 0;
xf = [kp(idx) flip(kp(idx))];
yf = [ki(idx) zeros(1,nnz(idx))];
fill(xf,yf,'g','EdgeColor','none')
hold on
plot(kp, zeros(size(ki)), 'b.')
plot(kp, ki, 'r.')
axis tight
xlabel('Gain k_p')
ylabel('Gain k_i')
title('Stability Bounds, k_i vs. k_p')
grid
Más respuestas (1)
Athanasios Paraskevopoulos
el 23 de Mzo. de 2024
kp = -10:0.1:10;
ki = zeros(size(kp));
for iter = 1:length(kp)
ki(iter) = 221*kp(iter) + 1326;
end
figure(1)
clf
hold on
% Plot the lines
plot(kp, zeros(size(ki)), 'b.')
plot(kp, ki, 'r.')
% Fill the area between the lines
x_fill = [kp, fliplr(kp)]; % Concatenate kp and a flipped version of kp
y_fill = [zeros(size(ki)), fliplr(ki)]; % Concatenate zeros and a flipped version of ki
fill(x_fill, y_fill, 'y', 'FaceAlpha', 0.5); % Fill with yellow color and some transparency
axis tight
xlabel('Gain k_p')
ylabel('Gain k_i')
title('Stability Bounds, k_i vs. k_p')
grid on
hold off
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!