No one has a clue?
Passing workspace variables to Simulink models running in external mode
3 views (last 30 days)
I have a problem involving sharing workspace variables with a Simulink model running in external mode, executed from a Matlab script (i.e. a function of the type function=run_mdl(…,…,…)).
The goal is to measure variables from a human experiment, that logs into a .mat file, and to use the measured data to playback in a subsequent simulink model, that has to run in external mode. The variables are matrices that contain up to 120k rows. This is unfortunate, because I know that I can pass variables as constants by using the following:
But if I try to do this in such large variables, it takes so long to pass big strings.
I tried a few approaches so far, none of which is completely satisfying:
1) Including the "From File" block in the library browser, loading the appropriate .mat file and processing the required columns. This is unsatisfactory because when the model runs in external mode it requires recompilation of the model to pass the correct .mat file (otherwise, it keeps the values of the .mat file at compilation; I discovered after some careful testing). I can script a rtwbuild command to avoid this problem, but this takes too long for what we would like, and I am bothered by the fact that I don't think that recompilation should be needed since I can pass to the simulink model a vector with pre-defined dimensions.
2) I tried using the "From Workspace" block in the library browser, but I did not find a way to instruct the simulink model to use the "current" workspace since I am running the model in external mode. I found this solution (<http://www.mathworks.com/matlabcentral/answers/94215-how-can-i-set-the-source-workspace-to-caller-when-using-a-the-sim-command-from-a-function-in-simul)>, which looked great, but the "sim" function does not work in external mode. I looked at possible arguments for set_param, to say something like set_param(ModelName,'SrcWorkspace','current'), but this does not seem to be an option.
Does anyone have suggestions on how to solve this problem?