フィルターのクリア

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

2 ビュー (過去 30 日間)
xavier soltner
xavier soltner 2021 年 4 月 27 日
回答済み: xavier soltner 2021 年 4 月 29 日
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 Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by