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

2 views (last 30 days)
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.
Danial Waleed
Danial Waleed on 26 Mar 2018
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.

Sign in to comment.

Answers (2)

Birdman on 26 Mar 2018
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:
Hope this helps. Let me know if it works for you.

Sign in to comment.

Walter Roberson
Walter Roberson on 27 Mar 2018
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
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 Comment
Danial Waleed
Danial Waleed on 27 Mar 2018
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!