exahange data between matlab script and simulink block diagram
3 views (last 30 days)
Show older comments
I have a simulink file which contains many subsystems, I need to implement the Genetic algorithm to optimize 20 variables in this simulink file, so the first thing I did is generating random binary numbers in the matlab file then convert it to decimal in a certain way as mentioned in the genetic algorithm. My questions are: 1- I want to send these numbers to the simulink block diagram instantly and run the simulink (from matlab)to get the output and feed back this output to the matlab file to do some calculations and repeat the previous steps until the output in the simulink reaches the desired value, how to send those values from matlab file to the simulink file?
2-I read that I can run the simulink in a parallel way, since my code should do the following: a- Generating a number of data sets each data set contains 20 numbers. b- send those data sets in a parallel way to the simulink in order to calculate the output for each data set. c- send the outputs to the matlab file to do some calculations, if the error is still high go to step (a). else stop the program and save the required data. Can any one help me to how to do this communication between matlab file and simulink block diagram? also, the simulink block diagram has many subsystems, connected together, since I read that in order to send something from matlab to simulink I must use set_param function, how to deal with those variables which will be sent from matlab as parameters? Could you please help me, Thank you, Sali
1 Comment
Sriram Narayanan
on 13 Aug 2015
Hi Sali,
If I am understanding your question correctly, you are trying to use the parameters you have defined in the script in your model.
Are you not able to execute the script which loads the data(variables) into the base workspace? You can then run the simulink model using that.
An even better way to do this would be to use a 'StartFcn' model callback in which you can run the script which defines the variables required for simulation. You can run your simulation and then either log the signals of interest or the parameters of interest and store them back in a MAT-file which could be loaded in your script (and would obviously change for each simulation) so that the new variable values are available every time you run the simulation.
Answers (0)
See Also
Categories
Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!