Effacer les filtres
Effacer les filtres

How to send any type of parameters in update-function to output-function in simulink s-function?

1 vue (au cours des 30 derniers jours)
I try to show 'ax' in output, so I send 'ax' to output by adding it to the state vector 'x'.
But, it is not a good idea when the size of 'ax' vector is increasing. It will increase computation time because dim. of state increases.
global 'ax' doesn't work at all.
any suggestions?
function sys=mdlUpdate(t,x,u)
dt = 0.01;
Td = u;
% Numerical Integration
x_prev = x(1);
x(1) = x(1) + Td*dt; % Euler integration
ax = (x(1)-x_prev)/dt;
x(2) = ax;
sys = [x(1) x(2)];
function sys=mdlOutputs(t,x,u)
ax = x(2);
sys = [x(1) ax];

Réponses (1)

Pavan Sahith
Pavan Sahith le 20 Oct 2023
Hello,
I understand you are trying to pass a parameter ‘ax’ in the update function to output function of the Simulink S-function block.
As a workaround you can try “ssSetUserData and “ssGetUserData functions which uses the S-function’s user data.
Please refer to this sample code to understand the use of ssSetUserData” and “ssGetUserData function.
%In update-function you can use these
% Retrieve 'ax' from the userdata field
% ‘gcb’- get current block.
userdata = ssGetUserData(gcb); % Get user data
ax = userdata.ax; % Access 'ax' from the user data
% Update 'ax' in the user data
userdata.ax = ax; % Update 'ax' in user data
ssSetUserData(gcb, userdata); % Set user data
% sample output-function can be like this
function sys = mdlOutputs(t, x, u)
% Retrieve 'ax' from the userdata field
userdata = ssGetUserData(gcb); % Get user data
ax = userdata.ax; % Access 'ax' from the user data
sys = [x(1); ax];
end
Please refer to the MathWorks documentation links to know more about
Hope it helps.

Catégories

En savoir plus sur Block and Blockset Authoring dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by