How do I shade area in between two functions?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 23 Mar 2024
Modificato: Voss
il 23 Mar 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 Commento
Voss
il 23 Mar 2024
Modificato: Voss
il 23 Mar 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
Più risposte (1)
Athanasios Paraskevopoulos
il 23 Mar 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 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!