Matlab Simulink and Reinforcement Learning Approach - matlab

I would like to create a project using a Matlab simulink environment model to find optimal parameters using reinforcement learning. Is it possible to export the environment data from matlab simulink and incorporate it into a python script or to create an interface to matlab simulink in order to train interactively with it? Or is there a better approach?
Unfortunately, this is rather vague, so I'm sorry, as I do not know what the matlab model will look like. It would also be helpful for me to see an example project or something along the lines of accessing Matlab Simulink data and reinforcement learning.
Thank you very much.

To create an interface with python script and the Simulink simulation, you can use MATLAB Engine for Python.
I could find a sample implementation in this blog. You can extend the simulate function in this example with an RL Agent to determine an action.

You can use simulink and generate coder from simulink. You must download simulink coder, matlab coder packages to generate code.

Related

Is there a possibility to import a KERAS model to Matlab without the Deep Learning Toolbox?

I have worked out a LSTM model and would like to incorporate it into a MATLAB framework. Via the Deep Learning Toolbox the functions importKerasLayers and importKerasNetwork can be called.
Is there also a way to implement the model without the Deep Learning Toolbox?
With a new version of MATLAB, it is possible to invoke Python from MATLAB. Check this URL https://in.mathworks.com/help/matlab/matlab_external/create-object-from-python-class.html#mw_c224a09a-f56b-48e5-b9ec-145388506204
I'm not sure, what you are trying to achieve by importing keras inside MATLAB. I guess, you may want to use MATLAB for your data preprocessing activities. If that is the case, you may complete preprocessing separately and save data in to numpy or pandas format to consume from Python.

Why doesn't a dataset created in matlab's simulink offer me get.Element function?

I'm doing a tutorial to learn matlab and simulink, and it came to a part where you run the .slx model from the script and extract data from it. The issue is that my matlab doesn't offer the same options for a dataset compared to the tutorial, specifically the get.Element option
picture to make it clearer:
enter image description here

Use Sim() command without coder.extrinsic in Matlab

Is there an alternative function to the sim() command oder a direct way executing a Simulink Model / a compiled version of it from Matlab without setting coder.extrinsic?
I want to execute a simulink model inside of an iterative Matlab-function. (Hence, speed matters dramatically). The used Simulink model contains a Dymola interface and hence, I cannot model it directly in Matlab. Another main Simulink model starts and iterates the Matlab functions and hence, simulating it leads the coder trying to compile it efficiently. By setting coder.extrinsic, of course I can use the sim command, but it is way too slow for its purpose. I thought about compiling the Simulink model as an alternative, but do not know if this would be a good approach
The structure looks as follows:
Simulink main model -> matlab functions -> simulink model
sim command needs MATLAB. So you need coder.extrinsic. There is no direct alternate way without coder.extrinsic to simulate a model. You can generate code from the model and call the generate code using coder.ceval functions. But if your goal is only to get more speed instead of getting stand-alone code you can set your model to run in accelerator mode and see whether that improves speed.

Generate equation from Simulink Model

I have a large simulink model with many source and sink blocks, many with only elementary arithmetic operations in between. I have been asked to document the equations behind the model. I am currently doing this manually and I am finding it rather slow and there is a relatively high chance of errors in the process.
Is there any way for Simulink to generate the equations (in MATLAB syntax for example) automatically?
There is no utility in MATLAB/Simulink that can do exactly what you are looking for (and I personally don't know of any third-party tools that can do this, either).
However, I think that your best bet might be to make use of Simulink Coder. This will allow you to convert your Simulink model to C code. From that code, you may be able to extract the equivalent equations more easily than you can by analyzing the Simulink model by hand.
The catch, though, is that Simulink Coder is an add-on package to base Simulink, so you may or may not have this tool available to you.

Simulink version of AnyLogic component

Does anybody know what components in Simulink (MATLAB package) are analogs for AnyLogic components? (e.g: source, buffer, delay, sink).
Or how can I easily simulate behavior of AnyLogic model in MATLAB?
Maybe there are some cool magic tools?
If you're asking whether or not there is an easy way to convert from an AnyLogic model to a Simulink model, I doubt it. I haven't seen any conversion tools like that.
I have a feeling you're just going to have to rebuild your AnyLogic model in Simulink if you want to simulate your models in MATLAB. I would start by looking through the Block List and Function List links on this Simulink documentation page. You should be able to find analogous components to those in your AnyLogic model.
AnyLogic is one of the best tools for business simulation and Matlab is the best engineering tool. But they have different notations.So in the most cases conversion is just impossible! E.g. to convert DE model of airport into Matlab.
My suggestion: use Matlab for engineering tasks and AnyLogic for business simulation.