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
0 个评论
采纳的回答
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
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
2024-3-23
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!