標籤:matlab 記憶體配置 c++ exception
最近在用c++和matlab 混合編程是遇到了一些問題,如下:
??? Unexpected Standard exception from MEX file.
What() is:c:program
Error in ==> mscale at 32
[rho,s] = matscale(abs(a),0.01);
Error in ==> utScaledExpm at 7
[s,junk,a] = mscale(a,‘noperm‘,‘safebal‘);
Error in ==> ssdata.utDiscretizeZOH at 171
s = utScaledExpm([[a b]*Ts; zeros(nu,nx+nu)]);
Error in ==> ssdata.trespSetUp at 104
[D,XMap] = utDiscretizeZOH(D,dt,XMap);
Error in ==> ltidata.timeresp at 78
[Dsim,dt,tf,SimInfo] =
trespSetUp(D,RespType,dt,tf,x0);
Error in ==> lti.step at 67
[y,t,focus] = timeresp(D,‘step‘,t);
Error in ==> step at 125
yout = step(sys,t);
關於異常,請參加:http://www.cplusplus.com/reference/exception/exception/
1. 直接在網上的程式或者直接用的別人的code,會由於配置以及環境問題導致問題,此處並不一定拋出異常,比較容易尋找;
2. 程式當時的Matlab版本不同與自己目前的Matlab版本不同,有導致拋出異常的可能性,並且自己也有經曆;
3.有時候,如果用C++的容器(list、vector等),如果size 或者迭代器使用不當也會導致越界訪問異常,特別是對於容器的邊界,尤其注意,本人曾在這裡不止吃了一次苦頭!
4. 因為記憶體配置與釋放問題,在程式運行幾次後,你的CPU佔用率很高的話,就應該考慮此原因,是不是忘記release resource了!
尋找錯誤的關鍵在於跟蹤與定位,切記哦!
關於C++與Matlab混合編程錯誤??? Unexpected Standard exception from MEX file.