Input ("u") index must be a positive integer in the expression: 1.5*u[n]-0.5*u[n-1]
Afficher commentaires plus anciens
I am running MATLAB R2013a and I am attempting to convert a project into C++ code. When I have my model opened in Simulink and hit Ctrl+B, I get the following error:
Input ("u") index must be a positive integer in the expression: 1.5*u[n]-0.5*u[n-1] in 'fcn' when used for code generation
I am not sure how to move past this error. I do not have much MATLAB experience so I am not sure what other information to include in this post. I saw in another post that a method for fixing this involves replacing the function with a switch statement, but I have not been able to figure out that, either.
Here is what the code to my function block in my mdl looks like:
Block {
BlockType Fcn
Name "Fcn"
Position [685, 339, 755, 371]
BackgroundColor "yellow"
Expr "1.5*u[n]-0.5*u[n-1]"
}
And I believe this chunk of code from an m-file might be related:
h_1a = Hmg(Sc_1a*Sf,th(1),Np(1),Tm1a,Td,1,Ta,Pa);
Out_1a = 1.5*h_1a(2*n)-0.5*h_1a(2*n-1);
h_1b = Hmg(Sc_1b*Sf,th(2),Np(2),Tm1b,Td,1,Ta,Pa);
Out_1b = 1.5*h_1b(2*n)-0.5*h_1b(2*n-1);
Out_1 = ((Np(1)*(H(1)-th(1))*(s(1)-th(1)))*Out_1a+(Np(2)*(H(1)-th(2))*(s(1)-th(2)))*Out_1b)/(Np(1)*(H(1)-th(1))*(s(1)-th(1))+Np(2)*(H(1)-th(2))*(s(1)-th(2)));
h_2 = Hmg(Sc*Sf,th(3),Np(3),Tm2,Out_1,2,Ta,Pa);
Out_2 = 1.5*h_2(2*n)-0.5*h_2(2*n-1);
h_3 = Hmg(Sc*Sf,th(4),Np(4),Tm3,Out_2,3,Ta,Pa);
Out_3 = 1.5*h_3(2*n)-0.5*h_3(2*n-1);
h_4 = Hmg(Sc*Sf,th(5),Np(5),Tm4,Out_3,4,Ta,Pa);
Out_4 = 1.5*h_4(2*n)-0.5*h_4(2*n-1);
h_5 = Hmg(Sc*Sf,th(6),Np(6),Tm5,Out_4,5,Ta,Pa);
Out_5 = 1.5*h_5(2*n)-0.5*h_5(2*n-1);
h_6 = Hmg(Sc*Sf,th(7),Np(7),Tm6,Out_5,6,Ta,Pa);
Out_6 = 1.5*h_6(2*n)-0.5*h_6(2*n-1);
I can provide more information about the project on request.
1 commentaire
Walter Roberson
le 29 Oct 2013
Can you disprove that n might be 0, or 1 ?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulink Functions 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!