The whole code purpose is to make a Unscented Kalman filter. I have this code working in Matlab, first I am trying to use it with Simulink, using Embedded MATLAB Function block.
Then I would like to make my M-code compliant so that I can used the embedded matlab capability to generate C code from it.
I am fearly new with Embeded Matlab functions. When I try to run my simulation, I have the following error codes:
******************************************************************
Subscripting into an mxArray is not supported.
Function 'Embedded MATLAB Function' (#18.1649.1660), line 52, column 29:
"temp(:,i-1)"
Subscripting into an mxArray is not supported.
Function 'Embedded MATLAB Function' (#18.1720.1733), line 55, column 29:
"temp(:,i-L-1)"
******************************************************************
I read that I need to assign data types to every variable, and I tried a few things but nothing seems to work. Here is the code that generates these errors, any suggestions/help would be greatly appreciated. I know that I will have to implement sqrtm matlab function myself because it is not supported by EMLC.
function [x_chap_kp1,P_kp1] = kalman(fm, Angle, x_chap, P, dt, Q, R, lambda, alpha, beta)
eml.extrinsic('sqrtm');
L = length(x_chap);
Khi = zeros([L 2*L+1]);
Khi(:,1) = x_chap;
temp = sqrtm((L+lambda)*P);
for i = 2:L+1
Khi(:,i) = x_chap + temp(:,i-1);
end
for i = L+2:2*L+1
Khi(:,i) = x_chap - temp(:,i-L-1);
end
*****************************************************************
I have another error code:
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
Here is the code:
Khi_kp1 = zeros(L,2*L+1);
for i = 1:2*L+1
Khi_kp1(:,i) = ...
mecanisation( Khi(1,i), Khi(2,i), Khi(3,i), Khi(4,i), Khi(5,i), ...
Khi(6,i), Khi(7,i), Khi(8,i), Khi(12,i), Khi(13,i), ...
Khi(14,i), Khi(15,i), Khi(16,i), Khi(17,i), ...
Roll, Pitch, Yaw, fmx, fmy, fmz, dt );
end
Where mecanisation is a sub-function:
function Khi_kp1 = mecanisation( Lon_k, Lat_k, Pos_k, Vg_k, Biais_a_k, Biais_w_k, ...
Roll, Pitch, Yaw, fmx, fmy, fmz, dt)
I've try to pass whole Khi array, like this:
Khi(:,i) = mecanisation( Khi(:,i), Roll, Pitch, Yaw, fmx, fmy, fmz, dt )
Where mecanisation is:
function Khi_kp1 = mecanisation( Khi_k, Roll, Pitch, Yaw, fmx, fmy, fmz, dt )
Lon_k = Khi_k(1);
Lat_k = Khi_k(2);
Pos_k = Khi_k(3:5);
Vg_k = Khi_k(6:8);
Biais_a_k = Khi_k(12:14);
Biais_w_k = Khi_k(15:17);
It gives me the error code:
Undefined function or variable 'Lat_k'. The first assignment to a local variable determines its class.
In fact I do not understand how can we deal with arrays in EML functions.
temp = P;
before the SQRTM call. That should do it.
If your matrix is non-defective, you can use an eigenvalue decomposition.
[V,D] = eig(A);
sqrtA = V*diag(sqrt(diag(D))) / V;
I'll see what I can do about getting SQRTM (using the same algorithm as
MATLAB) supported in a future release.
--
Mike
"Clement " <kek...@orange.fr> wrote in message
news:he5ttc$hln$1...@fred.mathworks.com...