Function got different results with the same inputs when directly called in MATLAB and called in exported .dll c++ library?
이전 댓글 표시
Hi everyone,
I'm working recently on some MATLAB-C++ combined programming work. I had successfully got my MATLAB function exported as a C++ dynamic library using the MATLAB Coder and have successfully called it in my C++ project. Everything seemed to be working fine.
However, then I found the results of calculation I got in the C++ program very strange so I checked it both in my C++ program and directly in MATLAB with the SAME function. To my surprise, they are different. For example, as I wanted to get a sum of some impulses with the following formular:
for i=1:N % elements of vector
for j=ps(i)*fs+1:(ps(i)+pw(i))*fs
curve(j)=curve(j)+lvl(i)*cos(double(2*pi*(j-ps(i)*fs-1)/fs*fo(i)))*exp(double(-alpha(i)*((j-ps(i)*fs-1)/fs)));
end
end
With the same input data N, ps, pw, fo, alpha and fs, what I got in my MATLAB function
[sampled_time,sampled_curve,sampled_freq,sampled_spec] = PIN_D_computation(rr,pw,ps,lvl,fo,fs,N,time_end,points)
was :
10.0000 -6.7010 4.1943 -2.4138 1.2275 8.5102 2.7659 -6.7054 ...
while what I got corresponding in the exported C++ function
extern void PIN_D_computation(emxArray_real_T *rr, emxArray_real_T *pw, emxArray_real_T *ps, emxArray_real_T *lvl, emxArray_real_T *fo, int32_T fs, int32_T N, int32_T time_end, int32_T points, emxArray_real_T *sampled_time, emxArray_real_T *sampled_curve, emxArray_real_T *sampled_freq, emxArray_real_T *sampled_spec);
was:
10.0000 -9.8999 2.7735 -3.0868 0.5030 8.6276 0.5921 -4.5843...
I guess this is due to a wrong configuration in the MATLAB Coder, but I cannnot make it sure.
I am using a PC with Intel Core2 Duo CPU E8400 @ 3GHz CPU and Win7 64 bit OS, working with a 32 bit MATLAB 2012a and a 32 bit MSVC compiler for my programming. My configuration for the MATLAB coder is:
Saturate on integer overflow: Yes
Support only purely-integer numbers: No
Support non-finite numbers: Yes
Code replacement library: Intel IPP(ISO) (I've tried Intel IPP(GNU) and Intel IPP(ANSI) as well but none works)
Test hardware is the same as production hardware: Yes
Device Vendor: Intel
Device Type: x86/Pentium
Largest atomic integer size: long
Largest atomic floating-point size: double
Signed integer division rounds to: floor
Language: C++
Could anyone maybe help me please on this issue? Thanks a lot!
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB Coder에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!