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!