Can a Level 2-s function block output a transfer function?

2 ビュー (過去 30 日間)
Danial Waleed
Danial Waleed 2018 年 3 月 26 日
コメント済み: Birdman 2018 年 3 月 27 日
I am working on a code whose output is a transfer function. I want to implement this code in Simulink and I am using the Level 2-sfunction block in order to implement it. The main issue is that once the code runs in Simulink. It gives me the following error.
" An error occurred while running the simulation and the simulation was terminated Caused by: Error evaluating registered method 'Outputs' of MATLAB S-Function 'run_1' in 'test/Level-2 MATLAB S-Function'. The following is the MATLAB call stack (file names and line numbers) that produced this error: ['C:\Previous computer\dani usb 2 backup\AUS University\Master\4th semester\MTR 690\MTR projects\Level-2 S function\ninteger\run_1.m'] [219] Invalid assignment in 'test/Level-2 MATLAB S-Function'. Data must be a numeric or logical array Component:Simulink | Category:Block error "
I would like to know if there is a way to output a transfer function using the Level 2-s function block. The reason I need it is because I need to keep on updating variables that need to be fed into the function.
  2 件のコメント
Birdman
Birdman 2018 年 3 月 26 日
Can you share your code?
Danial Waleed
Danial Waleed 2018 年 3 月 26 日
The code requires other dependent functions in order to work properly. I am sending you the files just extract them and run the test.slx file in order to see the simulink file. The code which the level-2 s function block uses is called run_1.m. thanks for your prompt feedback.

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

回答 (2 件)

Birdman
Birdman 2018 年 3 月 26 日
The problem seems to be with your output. You tried to output a datatype of tf, which is not supported by Simulink. Simulink works only with numerical values, therefore it is possible for you to work with them. In your run_1.m file, I changed the output accordingly. Please check that. I also set the Save output format to Array, in which you can easily see the coefficients being logged at every sample. You can change the formats according to your desire. The key change was this:
block.OutputPort(1).Data=[y.Numerator{1};y.Denominator{1}];
Hope this helps. Let me know if it works for you.
  6 件のコメント
Danial Waleed
Danial Waleed 2018 年 3 月 27 日
I will see what I can do.
Birdman
Birdman 2018 年 3 月 27 日
Ok, looking forward for your further questions.

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


Walter Roberson
Walter Roberson 2018 年 3 月 27 日
No, Level 2 S function must output signals, and tf are not signals. There is provision for creating custom data types for signals but the components are limited to double, int32, logical, char, and char with restricted values
https://www.mathworks.com/help/simulink/ug/simulink-data-class-extension-using-matlab-class-syntax.html
You could potentially create vectors of coefficients and current state and output those to be processed by a later S function or MATLAB Function Block, but you cannot output a tf and you cannot output a Simulink Block as a signal.
In some cases you might be able to use the S function to do the equivalent of set_param or to tune parameters of an existing transfer function block.
  1 件のコメント
Danial Waleed
Danial Waleed 2018 年 3 月 27 日
Understood, I think I will look into alternative than using Level-2 s function because there are so many limitations that I believe other alternatives could be better.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by