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,
Mostra commenti meno recenti
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.
Risposte (2)
Kaustubha Govind
il 10 Ago 2012
1 voto
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 Commenti
Yiqi Liu
il 13 Ago 2012
Kaustubha Govind
il 13 Ago 2012
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
il 16 Ago 2012
Modificato: Walter Roberson
il 16 Ago 2012
Yiqi Liu
il 16 Ago 2012
Modificato: Walter Roberson
il 16 Ago 2012
Kaustubha Govind
il 16 Ago 2012
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
il 17 Ago 2012
Modificato: Walter Roberson
il 17 Ago 2012
Kaustubha Govind
il 17 Ago 2012
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
il 20 Ago 2012
Kaustubha Govind
il 21 Ago 2012
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
il 23 Ago 2012
Isaac De La Cruz
il 13 Giu 2019
"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
il 22 Ago 2023
link to documentation is dead
Walter Roberson
il 22 Ago 2023
Yiqi Liu
il 12 Ago 2012
0 voti
1 Commento
Sathish Kumar
il 10 Giu 2014
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.
Categorie
Scopri di più su Configure Block Features for MATLAB S-Functions in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!