フィルターのクリア

What do I use instead of fopen and fprintf when running Matlab Coder to convert m-file to mex to C/C++

8 ビュー (過去 30 日間)
Hi,
I have a function which I am trying to use Matlab Coder to convert to mex and then to C code. It is a simple code, but it needs to write several of the local variables (which are arrays) to text files. In matlab this is easily done using fopen to create and open a file for writing, and then using fprintf to write the array to the opened file. However these functions are not supported in the Coder and I am not sure what to do.
My Matlab code is basically:
fid_u = fopen('velocity.txt','w');
for j = 1 : 100
fprintf(fid_u,'%16.12f\n', u(j,:));
end
fclose('all');
Does anyone know what I should change this to to be able to convert to a mex function and then C/C++ ?
Thanks!,
adam

回答 (2 件)

Ryan Livingston
Ryan Livingston 2013 年 5 月 13 日
FOPEN, FPRINTF and FCLOSE are supported for code generation starting in R2013a:
  2 件のコメント
Ali
Ali 2013 年 7 月 21 日
What about 2012a? it is not supported, so what to do?
Ryan Livingston
Ryan Livingston 2013 年 7 月 22 日
You can make use of coder.ceval() and coder.opaque() to call the C versions of FOPEN, FPRINTF and FCLOSE from your MATLAB code. Here is a demo doing this for FSCANF:
Alternatively, you could write the FOPEN/FPRINTF code directly in C in a custom C function and then just call that with coder.ceval.

サインインしてコメントする。


AlessioX
AlessioX 2016 年 3 月 18 日
FPRINTF, FOPEN and FCLOSE now in R2015b are available!
However FSCANF is not. I have to read a txt file, any alternatives to FSCANF?

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by