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
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!