Embedded matlab coder error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am interesting to simulate the following function in Embedded Matlab coder (model.slx):
function U = Func1 (C,E,F)
gt = coder.nullcopy(zeros(3,20));
U = coder.nullcopy(zeros(3,20));
for i=1:19
for j=1:20
gt(:,j)=EK(:,j)-Fk(:,j)-Uk(:,j)
U(:,j)=E(:,j)-F(:,j)-C(:,j)-gt(:,j);
Ek = [Ek , E(:,i)];
Fk= [Fk , F(:,i)];
Uk= [Uk , U(:,i)];
end
end
end
While Uk, Ek, and Uk are initialised in init.ma:
Fk=[0;0;0];
Uk=[0;0;0];
Qk=[0;0;0];
open_system(model);
when I compile init.m, the following errors are generated:
1/- Dimension 2 is fixed on the left-hand side but varies on the right ([3 x 20] ~= [3 x :?]). for 'Uk' 'Qk' and 'Ek'
2/- Undefined functions or variables 'Uk' 'Qk' and 'Ek'. The first assignment to a local variable determines its class.
I would greatly appreciate any sort of guidance in solving this problem.
Thank you.
0 comentarios
Respuestas (1)
Walter Roberson
el 28 de Jul. de 2016
Do not grow arrays incrementally in Embedded Coder: allocate the full size for them and fill them in.
You might need to assignin('base') for your variables; I am not at all sure that would be enough though.
Your code is not clear as to whether you expect those three variables to be "global": when you expand the variables inside the loop, are you expecting to always start with the 3 zeros each time the function is invoked, or are you expecting that the changed arrays will persist for the next execution of the function? If you are expecting the changed values to persist then you should be using "global" for the variables (and notice that your arrays would continue to grow because you always add on to the end of them no matter how big they started out.)
I suspect what you should be doing is using a From Workspace block to import the variables as signals and then include those signals as input ports to the function block. I am not sure whether you would also want a To Workspace block to save the variables afterwards; I suspect not.
4 comentarios
Walter Roberson
el 28 de Jul. de 2016
There had to have been a line before that in the error message. For example the line might have said something like
Attempted to access 1 element of data px whose runtime size is 0.
If that happens then it is because px is empty. A global variable that has not been initialized would be empty.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!