accessing workspace variables in embedded matlab function

4 次查看(过去 30 天)
I have a very large model that has numerous busses with lots of data. I enabled data logging on several busses and wrote a matlab function to post process the data logged in the workspace variable 'logsout'. However, I cannot log the data for the full simulation because I run out of memory. Therefore, I would like to run my post processing periodically on the 'logsout' workspace variable then clear the variable and and continue. I was hoping this would allow the simulation to complete without running out of memory.
However, I cannot seem to access the logsout variable in an embedded matlab function. Any suggestions?

回答(3 个)

timothy shands
timothy shands 2012-2-21
I should have said that I get the above error when I try to route one of the busses into an embedded matlab function.

Kaustubha Govind
Kaustubha Govind 2012-2-21
I'm not sure that it is safe to clear the 'logsout' variable during simulation, because the model might have it locked down. Additionally, I imagine that the model writes to an intermediate buffer and only populates the workspace at periodic intervals when the buffer gets full, so there is no guarantee that at time 't', all the data points corresponding to simulation from 0 to 't' have been logged to the workspace.
Have you considered instead saving and restoring the simulation state, so that you can break down your simulation time into short intervals, so that you can work on the 'logsout' piecemeal?

timothy shands
timothy shands 2012-2-21
That is an interesting solution. How would I do this. I am able to record about 19 seconds of data before I run out of memory. This is in a simulation which runs for 1900 seconds. So I would need to repeat this 100 times to get all the data. I would have to pause the simulation or something because I need to restart the sim where it left off for the next iteration of data.
Another solution would be to write a generic embedded matlab function which could parse the bus and write to file at each time step. However, when I tried this I get the following error (which I don't really understand):
Cannot propagate bus signal from output port 1 of 'MyModel/AMV' to input port 1 of 'MyModel/Embedded MATLAB Function' because this input port expects a non-bus signal. If the destination block is a bus-capable block, ensure that the block configuration and its input signal(s) meet the requirements for bus support. Please see Simulink documentation for further information on composite (i.e. bus) signals and their proper usage. Alternately, if the input bus signal is virtual; consists only of scalar elements, 1-D elements, or either row or column vectors; and all elements have the same data type, signal type, and sampling mode, consider inserting a Bus to Vector conversion block in the signal path. Otherwise, consider using a Bus Selector block in the signal path
  1 个评论
Kaustubha Govind
Kaustubha Govind 2012-2-22
1) Yes, you would need to repeat your simulation 100 times, for 19 seconds each time, by restoring the previous simulation state each time. For how - refer to the documentation link I pointed to in my original answer.
2) Are you using a non-virtual bus (should have a Simulink.Bus object corresponding to your signal)? Virtual buses are not supported as inputs to the Embedded MATLAB Function block. Also, if you are using non-virtual bus inputs, you need to configure the block input port accordingly. See http://www.mathworks.com/help/toolbox/simulink/ug/bq156zx.html

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by