Is it possible to pass a parameter which represents the "sampleTime" at a 2-Level S-function?

1 次查看(过去 30 天)
Is it possible to pass the sampleTime value as a parameter or an input into a S-function and to use this this value further in the S-function Outputs algorithm?
At the moment I programmed it in the following way: block.SampleTimes = [1e-3 0],
but I would like to have it like this: block.SampleTimes = [s_func_sample_time 0],
in order to specify the sample time somehow from outside of the S-function and to pass this value e.g. via the s_func_sample_time variable. Does there exist a possibility to do this either via the S-function parameter mask (block.NumDialogPrms) or via the S-function inputs (block.InputPort) or in any other way?
My aim is to use this parameter (s_func_sample_time value) further in the S-function Outputs function. E.g. in order to realize a discrete PI-controller. For the I-part it is necessary to know the sample time in order to integrate over the corret time interval. This sample time would be stored in the s_func_sample_time variable and I could use it in the Outputs algorithm.

采纳的回答

Guy Rouleau
Guy Rouleau 2012-7-5
IT should be possible to do something like:
block.SampleTimes = [block.DialogPrm(1).data 0];
to set the sample from a parameter.
It is not possible to set a discrete sample time of the s-function using a signal. For that, you would need to create a variable sample time s-function, because the value of a signal can change.
In your output function, you should be able to read block.SampleTimes and use the value.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Block and Blockset Authoring 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by