フィルターのクリア

Call embedded matlab function from command line

1 回表示 (過去 30 日間)
John Londt
John Londt 2014 年 1 月 30 日
編集済み: Kaustubha Govind 2014 年 3 月 31 日
I want to know if I can call an embedded Matlab function defined in my Simulink model from the Matlab command line. I'd like to have a unit test for each function, without having to run the simulation. Is there a way to do this?

採用された回答

Jacob Halbrooks
Jacob Halbrooks 2014 年 1 月 30 日
The code for the MATLAB Function block does not exist as a stand-alone file that you can call in MATLAB. However, you can programatically get the code in MATLAB as a string using the steps in Answer 102675. From there, you could write the text to a file and then call it.
  2 件のコメント
John Londt
John Londt 2014 年 1 月 30 日
This worked. Thank you! Just to summarize what I did:
- S = sfroot;
- B = S.find('Name','my_embedded_matlab_function');
- fid = fopen('test_function.m,'w');
- fprintf(fid,'%s',B.Script');
- fclos(fid);
Kaustubha Govind
Kaustubha Govind 2014 年 3 月 31 日
編集済み: Kaustubha Govind 2014 年 3 月 31 日
Please be aware that Simulink generates code from MATLAB Function blocks for faster execution. When you test the same function in MATLAB, you are running it using the MATLAB interpreter. Please know that there may be Differences in Behavior After Compiling MATLAB Code when using fixed-point data. In such cases, the safe thing to do would be to call the Simulink model using the SIM command to test.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by