Matlab function block Does not support 'fopen' code generation?

7 ビュー (過去 30 日間)
xingxingcui
xingxingcui 2022 年 3 月 4 日
コメント済み: xingxingcui 2022 年 3 月 4 日
I wrote a simple write binary file function with 'fopen' function for C code generation, but it is not supported in MATLAB function block, how can I solve it in simulink withn matlab function block ?(matlab coder generates it with no problem)
Also how to ensure the correct generation of string scalar or character vector variable length input? Thanks in advance
My model is attached.
function flag = fcn(binName)%#codegen
% coder.varsize('binName',[1,255]);
fid = fopen(binName,'w');
fprintf(fid,'%s','test');
fclose(fid);
flag = 1;
test in MATLAB 2021a

採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 4 日
The code believes that binName is numeric. You need to modify the datatype on the inport to be string. You will also need to configure the model to support dynamic memory allocation in MATLAB function blocks in order for string to be supported.
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 3 月 4 日
Simulink strings are like MATLAB strings, in that an individual string is considered to be a scalar object.
See attached.
xingxingcui
xingxingcui 2022 年 3 月 4 日
Thank you very much,@Walter Roberson

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by