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
Jan
Jan 2018년 2월 21일
The posted code does not contain a loop. So how can the loop be too slow?
Pulkit Sharma
Pulkit Sharma 2018년 2월 21일
The alternate code I wrote worked, but it was taking in excess of a day to solve.

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
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)));
  댓글 수: 2
Pulkit Sharma
Pulkit Sharma 2018년 2월 21일
Thank you, this was very helpful!
Pulkit Sharma
Pulkit Sharma 2018년 2월 21일
How do I create a (p,q) array for the tfPID, I need to plot the tf response with T and K.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by