How can I create an array of transfer functions without the for loop.
21 次查看(过去 30 天)
显示 更早的评论
I have been trying to create an array of transfer function (tfPID) where T and K vary using vectorization, because for loop is simply too slow. I would appreciate any help in this regard. The code I have been using is given below.
thanks!
clc
clear
A=[0 0 0 1 0 0 0 0 0;0 0 0 0 1 0 0 0 0;0 0 0 0 0 1 0 0 0;-0.003184 0 0 0 0 -0.0199 0 0 0.0199;0 0.0002985 0 0 0 0 0 0 0;0 0 -0.000398 0.00997 0 0 -0.00997 0 0;0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0];
B=[0 0 0;0 0 0;0 0 0;-1 0 0;0 -0.25 0;0 0 -0.5;1 0 0;0 1 0;0 0 1];
C=[1 0 0 0 0 0 0 0 0;0 1 0 0 0 0 0 0 0;0 0 1 0 0 0 0 0 0];
D=0;
sys = ss(A,B,C,D);
i=tf(sys);
xaxis=i(1,1);
yaxis=i(1,2);
zaxis=i(1,3);
K=-5001:5:5004;
T=-5001:5:5004;
p=1:2002;
q=1:2002;
j(p)=(0.6.*(T.^2).*K);
k(p)=4.8.*K.*T;
l(p)=9.6.*K;
num=[j;k;l];
q(p)=8.*T;
w(p)=0;
den=[q;w];
tfPID(p,q)=tf(num(:,p),den(:,q));
2 个评论
采纳的回答
Birdman
2018-2-21
Delete
tfPID(p,q)=tf(num(:,p),den(:,q));
and add these two lines at the end of your code:
num=num.';den=den.';
tfPID=tf(mat2cell(num(1:numel(p),:),ones(size(num,1),1)),mat2cell(den(1:numel(q),:),ones(size(den,1),1)));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!