clc;clear all;close all;k = 1:0.5:10;a = 1:0.5:5;n1 = numel(k);nump = kron(k,ones(1,length(a)))';denp = repmat([ones(n2,1), a.', zeros(n2,1)] ,n1, 1);w=[0.1,0.5,0.8,1,2,8,15,50,100];n2 = numel(a);delay=0;[rn,cn]=size(nump); [rd,cd]=size(denp); [rw,cw]=size(w);[rdel,cdel]=size(delay); if rw>1, w = w(:)';endif rn~=rd & (rn~=1 & rd~=1), endif rdel~=rn & rdel~=rd & rdel~=1,endi=sqrt(-1); s=i*w; mx = max(rn,rd);q=1; r=1; for h=1:mx, q=(rn>1)*h+(rn==1); r=(rd>1)*h+(rd==1); d=(rdel>1)*h+(rdel==1); upper = polyval(nump(q,:),s); lower = polyval(denp(r,:),s); cp(h,:)=(upper./lower).*exp(-s*delay(d)); end toc
MATLAB: How can i vectorize this for loop?
control systemMATLAB
Best Answer