Matlab Coder and saving variables to a file

How can I dump of variables to a file using Matlab Coder? It complains that fopen can't be used for this (I don't want to do coder.extrinsic).
Also, somewhat related, is there a way to inject C code into an m-file such that when Coder tries to generate code it simply copies that C code over to the C file unprocessed?

 採用された回答

Desiree
Desiree 2011 年 8 月 25 日

2 投票

You can use coder.ceval to call the C routine of FOPEN instead of the MATLAB implementation of FOPEN as this is not supported for code generation with MATLAB Coder.
There is a MATLAB Coder demo for reading from an external file which shows how to use this:
coderdemo_readfile
You can include custom code by adding with coder.config options, see:

1 件のコメント

CP
CP 2011 年 8 月 25 日
Thanks, don't have time to look at the demo in detail just now but it looks like it's exactly what I wanted.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 8 月 24 日

0 投票

Could you use coder.extrinsic('#include "source_to_inject.h"')

2 件のコメント

Kaustubha Govind
Kaustubha Govind 2011 年 8 月 25 日
Walter: No. The coder.extrinsic directive is used to call MATLAB functions unsupported for code generation. Desiree's suggestion of using coder.ceval is the right approach.
Walter Roberson
Walter Roberson 2011 年 8 月 25 日
Thanks. I haven't read enough messages about coder.* yet to have the pieces straightened out yet.

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

カテゴリ

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

質問済み:

CP
2011 年 8 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by