Coder Error with Simulink Embedded function using "fopen": Expected either a logical, char... Found an mxArray )

Embedded function: should check if the file is available to be written. If yes, file is written fid is a parameter u is an input
function Matlab_to_WM(u, fid)
coder.extrinsic('dlmwrite');
coder.extrinsic('fopen');
coder.extrinsic('fclose');
fid=fopen('D:\damien\Echange_donnees_System\Consigne_Retour_94A.txt', 'w');
if fid ~= -1 && fid ~= 2
dlmwrite('D:\damien\Echange_donnees_System\Consigne_Retour_94A.txt' , u , 'newline', 'pc');
end
fclose('all');
end
The result of "fopen" gives a mxArray (1 x 1) Then the test on fid value generate an error: "Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions."
This function, was working with the 2007b version and don't work anymore with 2012a version. Then, how to test a mxArray or to extract the value(1 x 1) as a double?

 採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 10 月 11 日

1 投票

I think you might need to pre-declare that fid is a double scalar. Does it work if you add "fid=0;" above the "fopen" line?

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by