f



ndefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y"

Hi everybody
I have a serious problem and i need your help. i use embedded matlab function in simulink to generate some matrices which i use as input to other bloc on simulink. But i got this error while  the simulation is running:

Undefined function or variable 'y'. The first assignment to a local variable determines its class.
Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2:
"y"

My code is 

function y = fcn(u)

Ap=[0.9580 0 0 0;0 0.9418 0 0;0 0 0.9048 0;0 0 0 0.9277];
Bp=[0.25 0;0.25 0;0 0.5;0 0.5];
Cp=[0.1678 0 0.9516 0;0 0.2329 0 0.2890];

[m1,n1]=size(Cp);
[n1,n_in]=size(Bp);
A_e=eye(n1+m1,n1+m1);
A_e(1:n1,1:n1)=Ap;
A_e(n1+1:n1+m1,1:n1)=Cp*Ap;
B_e=zeros(n1+m1,n_in);
B_e(1:n1,:)=Bp;
B_e(n1+1:n1+m1,:)=Cp*Bp;
C_e=zeros(m1,n1+m1);
C_e(:,n1+1:n1+m1)=eye(m1,m1);
 y(1:m1,:)=C_e;

 for kk=1:u-1;
     y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e; 

end
 
thank you so much
0
AGUEMON
7/16/2014 10:50:11 AM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies
3318 Views

Similar Articles

[PageSpeed] 59

On 07/16/2014 5:50 AM, AGUEMON wrote:
....
....

> ...i got this error while the simulation is
> running:
>
> Undefined function or variable 'y'. The first assignment to a local
> variable determines its class.
> Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2:
> "y"
>
....

> C_e(:,n1+1:n1+m1)=eye(m1,m1);
> y(1:m1,:)=C_e;
>
> for kk=1:u-1;
> y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e;
....

Never used the embedded toolboxen so this is purely a hypothesis -- I'd 
guess it, being intended for embedded, targets has far more restrictive 
rules for automagic allocation.

The first assignment is m1Xm1 but the for loop appears to extend that. 
I'd guess you need to preallocate the final full size.

Contact TMW Tech Support at <mathworks.com> for full detail if this 
doesn't help or lead you to being able to find the doc to support the 
supposition.

--
0
dpb
7/16/2014 12:25:23 PM
Reply:

Web resources about - ndefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y" - comp.soft-sys.matlab

Resources last updated: 2/5/2016 10:54:23 PM