필터 지우기
필터 지우기

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 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