Matrix dimensions do not match
Afficher commentaires plus anciens
Hi, I am using the ode 45 function in matlab for my statespace model. For the last line of the code i keep getting the error In an assignment A(I) = B, the number of elements in B and I must be the same. This is for the line u(i)=(sin(f*2*pi.*t+(alpha(i)/2)))+(sin(f*2*pi.*t-(alpha(i)/2))); I thought i already assigned the matrix sizes in the lines above. what is the problem
u=zeros(1,8000);
alpha=zeros(1,8000);
[t,x]=ode45(@ssmodel,t,x0);
for i=2:tstop*fsamp
%u is the input,pout is the output power which is state variable x5
%squared over Resistance
u(i)=u(i-1);
pout=(x(:,5).^2)/Rac;
%poutmean is just the average of pout
poutmean(i)=((i-1)/i)*mean(pout(i-1,1))+ (pout(i,1))/i;
%the error is fed to a PI controller, Kp is the proportional gain and
%Ki is the integral gain
e(i)=pref-poutmean(i);
alpha(i)=((Kp+Ki)*e(i))-(Kp*e(i-1))+(alpha(i-1));
%a limiter which limits the range of alpha to +-pi.
if(alpha(i)>pi)
alpha(i)=pi;
else if (alpha(i)<-pi)
alpha(i)=-pi;
end
end
u(i)=(sin(f*2*pi.*t+(alpha(i)/2)))+(sin(f*2*pi.*t-(alpha(i)/2)));}
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!