MATLAB Answers

0

Loading and saving huge matrices in Simulink

Asked by Brage Mothes on 20 Mar 2019
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!

  0 Comments

Sign in to comment.

2 Answers

Answer by Fangjun Jiang on 20 Mar 2019

Can't use .mat file? Try Simulink Data Dictionary.

  2 Comments

Maybe, but how do i do this and how do i read from and write to this from a Matlab Function Block?
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.



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.

  0 Comments

Sign in to comment.