Attempting to plot a 3 x 3 grid of plots

53 vues (au cours des 30 derniers jours)
William Kistler
William Kistler le 19 Fév 2021
Commenté : Star Strider le 20 Fév 2021
I am trying to plot the varying responses for a PID controller.
I have 3 values for K_p
I have 3 values for K_d
The function is already built in and pulls the K-values.
I need to create 9 subplots in a grid, but I'm terrible with for loops.
Should I create a vector for each?
Like this
Kp = [2.4 180 250];
Kd = [0 6.5 25];
What should the for loop be like?
for i = 1:length(Kp)
for j = 1:length(Kd)
plot([i:j]);
plot(time, response, 'k', 'LineWidth', 2)
end
end
All advice is appreciated, and forgive my lack of understanding. Thank You!

Réponses (1)

Star Strider
Star Strider le 19 Fév 2021
Try something like this:
time = linspace(0,2*pi);
response = @(Kp,Kd) sin(time*Kp) .* cos(time*Kd);
Kp = [2.4 180 250];
Kd = [0 6.5 25];
k = 0;
for i = 1:length(Kp)
for j = 1:length(Kd)
k = k+1;
subplot(3,3,k)
plot(time, response(Kp(i),Kd(j)), 'k', 'LineWidth', 2)
title(sprintf('Kp = %3.1f, Kd = %2.1f',Kp(i),Kd(j)))
end
end
Adapt that to plot what you want to plot. Make appropriate changes to get the result you want.
  2 commentaires
William Kistler
William Kistler le 20 Fév 2021
Your code runs elegantly on its own. Thank you for your help.
Unfortunately, due to the nature of the code we were given as part of the assignment, it isn't compatible.
I have attached the code to this message on the off chance that someone wants to give it a shot
Star Strider
Star Strider le 20 Fév 2021
I have no idea what you’re referring to. I don’t see anything similar in the .m file.
I’ll delete my Answer in a few hours.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by