I have created a Matlab class that needs to pull parameters from a database. The class has a function that makes a connection to the database and queries the appropriate data. It is called once, when the class is initialized. The class and connection works when I run it in the command window, however I would like the class to work as a block in a Simulink file.
Below is the code for the function. It was created with the help of the databaseExplorer. It uses commands from the database toolbox
function data = db_load_query(obj)
conn = database('simAC01','******','*******');
query = sprintf(['SELECT P, R, C, Rm, Cm, Tm, Tz ' ...
'FROM simAC01.dbo.configs ' ...
'WHERE id in (SELECT cfg_id ' ...
'FROM simAC01.dbo.loads ' ...
'WHERE sim_id = %d)'],obj.simID);
data = fetch(conn,query);
clear conn query
When I try and run the class as a simulink block, I get this error:
I have tried running the block in interpreted mode but the error stayed pretty much the same.
I understand that the database function I am currently using can't be generated into code that is compatible with Simulink. I was wondering what functions should I be using or is there a way to make simulink work with the existing code.
Thanks for your time,