How do I call a custom Matlab class method in a Simulink block?
Mostrar comentarios más antiguos
I am trying to create a Simulink model that uses an instance of a custom Matlab class from the workspace to process some data in the block diagram. For example, I would like to create a "Reaction" block in my Simulink model that takes two inputs (T and F) and uses the dFdt method of a class instance from the MATLAB workspace to output dFdt(T,F) (simplified example code below).
This is different than this question in that I do not want to pass the custom object as an output of the Simulink block.
The answers to this question and this question seem to imply that this is possible using 'UserData', but it is not clear to me how.
If this is even possible, how would I do it? Thanks in advance!
Example class definition
classdef Rxn < handle
properties
k = 0;
Ea = 0;
end
methods
function r = Rxn(k,Ea)
r.k = k;
r.Ea = Ea;
end
function dFdt = dwdt(obj,F,T)
dFdt = obj.k * exp(-obj.Ea/(8.314*T))*(1-F)
end
end
end
Desired script format
materials = [Rxn(1,10000), Rxn(0.1,20000)];
for i = 1:length(materials)
R = materials(i);
% Call simulink model and use 'R.dFdt(F,T)' in Simulink block
end
3 comentarios
Kaustubha Govind
el 15 de Jul. de 2013
How is R.dFdt(F,T) used in the model? Did you want to set it as the value of a block parameter?
Ryan G
el 15 de Jul. de 2013
Where would the simulink model use this data? Would it be a parameter or input port? It looks like each loop iteration the simulation is run with a single parameter (result of R.dFdt). If this is the case you should be able to do something like:
1) define parameter in Simulink as a variable, say x
2) x = R.dFdt;
3) run the model.
This should work as long as you run the script as a script and not a function. Make sense?
Tyler V
el 15 de Jul. de 2013
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Code Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!