MATLAB: Plot settling time based on damping ratio changes

control

I want to draw settling time plot, based on zeta changes. (ST-Zeta plot)
I wrote this code for that purpose and it works well:
clc;
clear;
hold on
wn = 1;
a = wn .^ 2;
for zeta = 0:0.001:1
b = 2 * wn * zeta;
G = tf(a, [1 b a]);
s = stepinfo(G);
st = s(1).SettlingTime;
plot(zeta, st, '.')
end
But I guess its not very good code, and there is a better one (like some commands or options). So please help me to make it better.
Thanks in advance.

Best Answer

Your code can be improved by its time consumption. This code's elapsed time is:
tic
for zeta = 0:0.001:1
b = 2 * wn * zeta;
G = tf(a, [1 b a]);
s = stepinfo(G);
st = s(1).SettlingTime;
plot(zeta, st, '.')
end
toc
>> 5.195815 seconds.
But if we improve it as follows:
wn = 1;
a = wn .^ 2;
zeta = 0:0.001:1;
st=zeros(1,numel(zeta));
tic
for i=1:numel(zeta)
b = 2 * wn * zeta(i);
G = tf(a, [1 b a]);
s = stepinfo(G);
st(i) = s.SettlingTime;
end
plot(zeta,st,'.')
toc
>> 2.531978 seconds.
Hope this helps.