How to plot multiple curves in the same graph window?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aishwarya Govekar
am 15 Mär. 2020
Kommentiert: Star Strider
am 16 Mär. 2020
I want to plot graphs for multiple Kp values for a proportional controller. I tried using for loop to perform this. But I didn't get the output.Below, I attach the code which I have written for your reference. Please guide me on this. If you can tell me if there's any other way to do it, then that would be great.
Kindly reply asap.
Thank you.
5 Kommentare
dpb
am 15 Mär. 2020
Just paste short demo code as text, use the code button to format ... much easier than having to download a file and open it externally.
For figures, SaveAs a .jpg and then attach the immage with the picture icon at the INSERT group.
I'll guess just from the words you didn't use "hold on" after the first plot to add subsequent to the same axes...
Akzeptierte Antwort
Star Strider
am 15 Mär. 2020
Try this:
J=20.48*10e-6;
b=0.702;
kt=14.70;
kb=0.48;
R=1.6;
L=0.02*0.001;
num=kt;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+(kb*kt))];
kp=0:50:300; %plotting graph for P controller with Kp values in steps of 50
for k = 1:numel(kp)
ki=0;
kd=0;
numc=[kd,kp(k),ki];
denc=[0 1];
numa=conv(num,numc);
dena=conv(den,denc);
[numac,denac]=cloop(numa,dena);
sys = tf(numac,denac)
[y{k},t{k}] = step(sys);
% QL(k,:) = [min(y{k}), max(y{k})] % Information
end
figure
hold on
for k = 2:numel(y)
plot(t{k}, y{k})
end
hold off
xlabel('time(sec)'), ylabel('velocity(rad/sec)')
title ('pid control');
grid
It is necessary to create a system object to use the step funciton. The first step output is uniformly zero, and that causes problems with the plot. Start with the second one instead.
Also, use feedback rather than cloop (that has been deprecated).
8 Kommentare
Aishwarya Govekar
am 16 Mär. 2020
Bearbeitet: Aishwarya Govekar
am 16 Mär. 2020
Star Strider
am 16 Mär. 2020
To change the axis limits use the xlim, ylim or axis functions. To set limits on axes that are already plotted, see the documentation on Axes Properties.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!