MATLAB system. The ' tf ' class does not support code generation.
古いコメントを表示
Hello everyone, When I want to do a Matlab system in Simulink, I encountered some errors.

Then this is my Function code
function out = NF(in,f_back12)
%#codegen
f1=f_back12;
Wr=2*pi*f1;
Sr=0.0707;
testNF=tf([1 (2*Wr*Sr) Wr^2],[1 (2*Wr*0.707) Wr^2]);
out=in*testNF;
end
Finally, it is an error occurred.

I want to how to generate the transfer function in Function?
Please help me, thank you
4 件のコメント
Ryan Rizzo
2018 年 3 月 20 日
Same problem here! Did you solve this?
Bartha Balazs
2018 年 4 月 11 日
I'm facing the sane issue :( did you found any solution ?
punit mishra
2021 年 1 月 6 日
same problem here
Mathieu NOE
2021 年 1 月 6 日
hello
if I were you, I would discretize all my filters in a script (if you start with continuous model , use c2dm )
then pass the parameters to the "discrete filter" block.
回答 (2 件)
Mohamed
2023 年 3 月 20 日
0 投票
try to use this coder.extrinsic("tf")
1 件のコメント
Taleb Vahabzadeh
2023 年 7 月 3 日
Thanks Mohamed.
Saurabh
2024 年 8 月 1 日
Hi Zhao,
So, the objective is to generate code for the ‘tf’ class which is used inside the MATLAB Function block and when doing so it’s throwing an error that the ‘tf’ class does not support code generation.
The lines in the provided function that do not support code generation are definition of ‘testNF’.
The same can be found here:
The possible workaround for this is to define a separate m-function on the path:
function testNF = mytf(Wr, Sr,)
testNF = tf([1 (2*Wr*Sr) Wr^2],[1 (2*Wr*0.707) Wr^2]);
end
function out = NF(in,f_back12)
coder.extrinsic(‘mytf’)
%#codegen
f1=f_back12;
Wr=2*pi*f1;
Sr=0.0707;
testNF=mytf(Wr, Sr)
out=in*testNF;
end
‘coder.extrinsic’ declares a function as extrinsic and executes it in MATLAB. For more information about ‘coder.extrinsic’ refer to this link: https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html?s_tid=doc_ta
Alternatively, one can use a ‘Transfer function’ block outside the ‘MATLAB function’ block and provide the input directly to the Function block, as discussed here:
I hope this was helpful.
カテゴリ
ヘルプ センター および File Exchange で Simulink Coder についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!