Coder. Error due mismatched varying sizes
2 views (last 30 days)
Show older comments
Good evening. I made the function NEOEKF and then tried to convert to C++ with coder, but I got the following warning:
57 Size mismatch (size [:? x 1] ~= size [4 x 1]). Mismatched varying and fixed sizes indicate a probable run-time error. If this diagnostic is incorrect, use indexing to explicitly make the varying size fixed.
Does any one can support me how to fix it? Refer to line 57
Thank you in advance.
regards Willy
function [DIST,VEL,RB] = NEOEKF(dT,T2)
Mo = 030;
dT = 20;
T2 = 360;
Xs = [0 0 4 0];
yseg = 2025.371/3600;
F = [1 0 0 0;0 1 0 0;dT 0 1 0 ;0 dT 0 1];
dd= 100;
dve= 15;
P = [dd^2 0 0 0;
0 dd^2 0 0;
0 0 dve^2 0;
0 0 0 dve^2];
v = 0.5;
R = pi/180*v^2;
X = [];
X = [15000*sin(Mo*pi/180) 15000*cos(Mo*pi/180) 0 0]';
I=eye(4);
Q = 15*[0.5*dT^3 0 0.25*dT^4 0;0 0.5*dT^3 0 0.25*dT^4;...
dT^2 0 0.5*dT^3 0;0 dT^2 0 0.5*dT^3];
DIST = size(T2);
VEL = size(T2);
RB = size(T2);
z = 30:0.4:34;
for k = 1:1:10
X(:,k+1) = F*X(:,k);
P_ = F*P*F'+ Q;
sx = X(1,k);
sy = X(2,k);
h = atan2(sx,sy);
if h<0
h = h + 2*pi;
elseif h>2*pi
h = h - 2*pi;
end
H = [sy/(sx^2 + sy^2) -sx/(sx^2 + sy^2) 0 0];
g = [cos(z(k))/(X(1)*sin(z(k))+ X(2,k+1)*cos(z(k))) -sin(z(k))/(X(1,k+1)*...
sin(z(k))+ X(2,k+1)*cos(z(k))) 0 0];
S = H*P_*H'+ R;
G = P_*H'/S;
X(:,k+1) = X(:,k+1)+ G*(z(k) - h); % Line 57
P =(I - G*g)*P_*(I - G*g)' + G*R*G';
DIST(k+1) = sqrt(X(1,k+1).^2 + X(2,k+1).^2);
VEL(k+1) = sqrt((X(3,k+1) + Xs(3)).^2 + (X(4,k+1) + Xs(4)).^2)/yseg;
RB(k+1) = atan2(X(3,k+1)+ Xs(3),X(4,k+1) + Xs(4))*180/pi;
RB(k+1) = round(RB(k+1));
if RB(k+1)<0
RB(k+1) = RB(k+1) + 360;
elseif RB(k+1) > 360;
RB(k+1) = RB(k+1) - 360;
end
X(:,k) = [X(:,k)];
end
2 Comments
Image Analyst
on 4 Dec 2012
Guillermo, to get your code to show up on separate lines, you can highlight the code and click the {}Code icon to make it look like code. That is far better than double spacing your code. Give it a try. Edit, remove blank lines, highlight, then click {}Code and Save.
Answers (1)
Walter Roberson
on 4 Dec 2012
Your z values are not integral, so z(k) is not integral, and h is not integral, so z(k)-h is not integral. But you have G() at that expression. G appears to be an array rather than a function, so I do not understand why it does not complain about indexing at a non-integral value ?
3 Comments
Walter Roberson
on 4 Dec 2012
Do no extend your X array at run-time. Initialize it to be its final size as the very first time you assign to X, using zeros().
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!