I hope my keywords describe my situation. Basically, I'm working with SMC (Sliding Mode Control) in Simulink using simulink blocks and S Function blocks. Now, I want to use DE (Differential Evolution) algorithm, to determine the parameters of SMC that gives the best results. DE implemented by two m files, one of them contain a function for objective function (this need by DE), and the other one contain the rest of DE algorithm, used to running. What I did, is that, I converted one m file, to s function because it need some variables from the Simulink Model, my question is that, now I want to use the value of the objective function in the other m file (DE algorithm) to run the DE to make some iterations. Hopefully, I'm clear. I found some stuff here, but it seems, I'm looking exactly for the opposite scenario.
Asked
Active
Viewed 364 times
0
-
So, my first thought is that there is some special reason that you cannot convert the second file to a Simulink s-function? In that case, I'm afraid your only option might be to manually save each needed variable to the workspace at each time step. You should be able to do this using [`assignin`](http://www.mathworks.com/help/matlab/ref/assignin.html). – May 09 '15 at 01:42
1 Answers
0
Let's define your two DE files first:
DE1: contains a function for objective function;
DE2: contains the rest of DE algorithm.
As far as I understood, you have converted DE2 into S-function, and wanted to use the variables in DE1 for iterations.
- If the variables in DE1 are constant, then using constant block in Simlink may solve your problem. Simply put those variables in the constant block and connect to DE2 as inputs.
- If the variables in DE1 are varying during the iteration, then converting DE1 into S-function should be the right way to do it.

Zhang Tianbao
- 521
- 1
- 6
- 8