Loading and saving huge matrices in Simulink

6 views (last 30 days)
Hello,
I am working with a reinforcement learning model in Simulink. For the memory i need to use huge 6D matrices.
Currently I create these matrices in Matlab and load them into my Matlab Function Block in Simulink using the following code:
persistent Q
if isempty(Q)
Q = evalin('base', 'q8');
end
But this is very time consuming, and i have problems saving the matrix back into my Matlab workspace afterwards.
Anyone know of an easier way of working with big matrices in Simulink, that can be loaded and saved?
Examples are greatly appreciated!
Thanks!

Answers (2)

Fangjun Jiang
Fangjun Jiang on 20 Mar 2019
Can't use .mat file? Try Simulink Data Dictionary.
  2 Comments
Brage Mothes
Brage Mothes on 20 Mar 2019
Maybe, but how do i do this and how do i read from and write to this from a Matlab Function Block?
Fangjun Jiang
Fangjun Jiang on 21 Mar 2019
If your current approach works but slow, the first thing I would try is to save the matraces into a .mat file. Next time, you can use load() instead of evalin() to load the data. I am not sure what you mean by "have problems saving the matrix back into my Matlab workspace afterwards".
The next thing is try SLDD. Go to File->Model Properties->Link to Data Dictionary. Once you finished, just think of the data is loaded from the .sldd file rather than the .mat file.

Sign in to comment.


Emmanouil Tzorakoleftherakis
On a separate note, it looks like you are implementing Q-learning (?). Q-learning uses tables, which do not scale well when your problem is high-dimensional. Maybe switching to a function approximator (e.g. neural network) would help with scaling.
You could also use some of the built-in reinforcement learning algorithms from Reinforcemen Learning Toolbox (e.g. DQN).
Hope this helps.

Categories

Find more on Startup and Shutdown 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!