Can a Level 2-s function block output a transfer function?
1 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!