How do I shade area in between two functions?

4 Ansichten (letzte 30 Tage)
Richard
Richard am 23 Mär. 2024
Bearbeitet: Voss am 23 Mär. 2024
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

Akzeptierte Antwort

Voss
Voss am 23 Mär. 2024
Bearbeitet: Voss am 23 Mär. 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 Kommentar
Voss
Voss am 23 Mär. 2024
Bearbeitet: Voss am 23 Mär. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Athanasios Paraskevopoulos
Athanasios Paraskevopoulos am 23 Mär. 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

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by