How do I write a MATLAB file S-function when the output width depends on the input width and input value?
Afficher commentaires plus anciens
I want to write a MATLAB file S-function that allows dynamic input and output width; besides, the output width depends on the input width and input value. For example, my mdlInitializeSizes routine contains the following code fragment:
sizes.NumOutputs = -1;
sizes.NumInputs = -1;
sizes.DirFeedthrough = 1;
and my mdlOutputs routine looks like the following:
function sys=mdlOutputs(t,x,u)
if (length(u) - 1) > 4 %% Input width larger than 4
if u(1) == 1
y = [1;u(2:5)]; %% Assign first four input elements to output
else
y = [0;u(2:length(u))]; %% Assign all input elements to output
end
else %% Input width less than or equal to 4
y = [0;u(2:length(u))]; %% Assign all input elements to output
end
sys = y;
However, the S-function does not work when the output width is different from the input width. For example, when the input is [1, 2, 3, 4, 5, 6], the output is supposed to be [1, 2, 3, 4, 5]; but I receive the following error message:
Output returned by S-function 'modified_dac' in block 'customer_dec/S-Function'
during flag=3 call must be a real vector of length 6
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Nonlinear Operators dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!