How do I shade area in between two functions?

4 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2024-3-23
编辑:Voss 2024-3-23
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 个评论
Voss
Voss 2024-3-23
编辑:Voss 2024-3-23
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 个)

Athanasios Paraskevopoulos
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

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by