MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

1

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

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
2018 年 3 月 26 日
Can you share your code?
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.

サインイン to comment.

2 件の回答

回答者: 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 件のコメント

Birdman
2018 年 3 月 27 日
Simulink does not want to work with variable size inputs/outputs. Even if you have a variable sized output, you need to specify an upper limit for it. Therefore, I suggest you to specify an upper limit and work according to that.
I will see what I can do.
Birdman
2018 年 3 月 27 日
Ok, looking forward for your further questions.

サインイン to comment.


回答者: 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 件のコメント

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.

サインイン to comment.



Translated by