Hi, everybody, I got one problem when using S-function dynamic output. The input dimensions of my S function module is constant, i.e., 4,
古いコメントを表示
Hi, everybody, I got one problem when using S-function dynamic output. The input dimensions of my S function module is constant, i.e., 4, But the dimensions of my output is dynamic, it is relative to but not the same as the values of one input. Thus, my question is how I set the number of dimension for output in a dynamic or variable way. And I check the matlab document, What it says is the dimension of output is needed to be the same as the dimension of input if we get to use variable output dimensions.
回答 (2 件)
Kaustubha Govind
2012 年 8 月 10 日
1 投票
You haven't mentioned if you're writing a MATLAB S-function, or a C S-function, but this page in the documentation points to demos for both types of S-functions with variable-sized outputs.
13 件のコメント
Yiqi Liu
2012 年 8 月 13 日
Kaustubha Govind
2012 年 8 月 13 日
Variable-size signals in Simulink require you to specify the maximum (upper limit) size that the signal can attain. So you need to set the maximum size in SetInputPortDims(), and set the actual size based on the input value in the Outputs() function by assigning block.OutputPort(1).CurrentDimensions.
Yiqi Liu
2012 年 8 月 16 日
編集済み: Walter Roberson
2012 年 8 月 16 日
Yiqi Liu
2012 年 8 月 16 日
編集済み: Walter Roberson
2012 年 8 月 16 日
Kaustubha Govind
2012 年 8 月 16 日
You've set your sample time to be inherited:
block.SampleTimes = [-1 0];
Perhaps the blocks connected to the input/output of the S-function are configured for continuous-time? Turning on Sample Time Colors might help.
Yiqi Liu
2012 年 8 月 17 日
編集済み: Walter Roberson
2012 年 8 月 17 日
Kaustubha Govind
2012 年 8 月 17 日
Please see the demo I pointed in my initial answer which shows you how to setup maximum dimensions, etc. As I commented before:
"Variable-size signals in Simulink require you to specify the maximum (upper limit) size that the signal can attain. So you need to set the maximum size in SetInputPortDims(), and set the actual size based on the input value in the Outputs() function by assigning block.OutputPort(1).CurrentDimensions."
Please look at SetInputPortDims() and Outputs() function in the demo that I pointed to.
Yiqi Liu
2012 年 8 月 20 日
Kaustubha Govind
2012 年 8 月 21 日
Yiqi: What version of MATLAB are you using? Are you saying that when you enter "msfcndemo_varsize" at your MATLAB prompt, the demo doesn't open up? Note that variable-size signals were introduced in Simulink in R2009b, so if you don't have access to that model, it is likely that you are using an older version, and cannot avail of this feature.
Yiqi Liu
2012 年 8 月 23 日
Isaac De La Cruz
2019 年 6 月 13 日
"Variable-size signals in Simulink require you to specify the maximum (upper limit) size that the signal can attain. So you need to set the maximum size in SetInputPortDims(), and set the actual size based on the input value in the Outputs() function by assigning block.OutputPort(1).CurrentDimensions."
Is this also valid for C S-functions? I am trying to develop a C S-function with the same funcionality, but I can't set the size of the output to be bigger than the initial size set using ssSetOutputPortWidth. Here is the error I get:

Richard Crozier
2023 年 8 月 22 日
link to documentation is dead
Walter Roberson
2023 年 8 月 22 日
Yiqi Liu
2012 年 8 月 12 日
0 投票
1 件のコメント
Sathish Kumar
2014 年 6 月 10 日
Yes you can get multi-dimensional output out of a 1D input. Just remember to set the correct output port dimension.( block.OutputPort(portid).Dimensions=dim, where dim=[m,n] for an mxn output.), It your outsize changes based on the logic in your program set the output port dimension to -1.
カテゴリ
ヘルプ センター および File Exchange で Create MATLAB S-Functions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!