Matlab Coder does not properly execute/support mldivide (a.k.a "\") ?

2 次查看(过去 30 天)
Hi,
I'm having trouble with Matlab Coder who seems to not properly execute the mldivide(a,b) function..
The code is supposed to calculate the misplacement of a workpiece position. The part I have trouble with is the following :
% construct vector and matrices, around current estimate of p, to have: dmes=V+M*pest => pest=M\(dmes-V)
V=d(pest)-pest(1)*dd_dx(pest)-pest(2)*dd_dy(pest)-pest(3)*dd_dtheta(pest);
M=[dd_dx(pest), dd_dy(pest), dd_dtheta(pest)];
fprintf("V1=%f V2=%f V3=%f\n",V(1),V(2),V(3));
fprintf("M11=%f M12=%f M13=%f\n",M(1,1),M(1,2),M(1,3));
fprintf("M21=%f M22=%f M23=%f\n",M(2,1),M(2,2),M(2,3));
fprintf("M31=%f M32=%f M33=%f\n",M(3,1),M(3,2),M(3,3));
% resolve for new value of pest
tempVar=(dmes-V);
pest=mldivide(M,tempVar);
%pest=M\(dmes-V);
fprintf("pest1=%f pest2=%f pest3=%f\n",pest(1),pest(2),pest(3));
When directly executing the code with Matlab I have the following output:
dmes1=0.000250 dmes2=-0.000360 dmes3=0.000156
V1=0.000000 V2=0.000000 V3=0.000000
M11=-0.707107 M12=0.707107 M13=19.996980
M21=-0.707107 M22=-0.707107 M23=19.996980
M31=1.000000 M32=0.000000 M33=20.000000
%execution of mldivide in matlab
pest1=0.000124 pest2=0.000431 pest3=0.000002
Wich give me the correct pest(=PositionEstimation) of the workpiece, but when I execute it in my C++ program I have the following :
dmes1=0.000250 dmes2=-0.000360 dmes3=0.000156
V1=0.000000 V2=0.000000 V3=0.000000
M11=-0.707107 M12=0.707107 M13=19.996980
M21=-0.707107 M22=-0.707107 M23=19.996980
M31=1.000000 M32=0.000000 M33=20.000000
%execution of mldivide in C++ programm
pest1=nan pest2=nan pest3=nan
Anyone know the reason for this to happen or any fix ?
Regards,
Xavier
  1 个评论
Ji Lee
Ji Lee 2021-4-28
It seems like there is some amount of code missing from the snippet posted. Namely, the variables used on the first line of code (right-hand side of the assignment into V) look undefined. Would you be able to fill in the missing gap(s)?

请先登录,再进行评论。

采纳的回答

xavier soltner
xavier soltner 2021-4-29
Ok I find out the problem : mldivide(A,B) does not support the input if A or B contain NaN value, wich I didn't know..
When I was doing my test in Matlab, my input variable (A and B) was completely defined with value, wich was not the case when I was compiling with the Coder where A and B was of size (500,3) with undefined value in it...
Maybe I should read the documentation more carefully the next time...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by