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

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일

0 개 추천

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

Thank you, the first problem is understood(Error alerts are not smart enough), the second I still do not know how to configure, I tried according to this scheme, but still can not solve, I hope to get your guidance again.
function flag = fcn(binName)%#codegen
assert(length(binName)<255);
% coder.varsize('binName',[1,255]);
fid = fopen(binName,'w');
fprintf(fid,'%s','test');
fclose(fid);
flag = 1;
Simulink strings are like MATLAB strings, in that an individual string is considered to be a scalar object.
See attached.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 3월 4일

댓글:

2022년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by