How to persist variables in Simulink to prevent long compilation time at each simulation start?

조회 수: 37 (최근 30일)
Amr
Amr 2025년 11월 24일 12:48
댓글: Amr 2025년 12월 8일 9:03
I have big data (about 6 Gb) that I need to use in n-lookup table in simulink. each time i run the simulation, it take long to compile the model even the model itself is very simple.
I tried Fast restart mode, it did the job. However, i can not modify anything in the model.
I tried to load the big variables in the model workspace, but still long compilation time is taken at the beginning of each simulation.
So, Is there anything I can do that will load the variables into simulink and keep then there as long as simulink is open? to reduce the compilation time
  댓글 수: 2
Anumeha
Anumeha 2025년 12월 8일 8:34
Hi Amr,
As per my understanding, you are tryring to persist a variable for an open session in simulink. The long compilation time could sometimes be due to multiple issues, which is a bit hard to judge without the data or the model. You could try creating a lookup table in your model. I tried the following steps with some random data:
  1. Save the data in a .mat file.
bigData = rand(2000, 2000, 10);
save('bigData.mat', 'bigData');
load('bigData.mat');
2. Import the data to Model Explorer>Model Workspace. Right click and select the .mat file within import.
3. Within the model, place an “n-D lookup table” block.
4. Define breakpoints according to your data size.
bp1 = linspace(0, 1, 2000);
bp2 = linspace(0, 1, 2000);
bp3 = linspace(0, 1, 10);
5. Set your variable in Table data.
For me, the compilation time was faster from the second go using this approach. Hope this works for you as well.
Amr
Amr 2025년 12월 8일 9:03
thanks for your comment.
I tried that and I did not see any difference. Here what I did
  1. prepare data
Nx = 400; % 500^3 is extremely large (125e6 points)
Ny = 400;
Nz = 400;
x = linspace(0, 1, Nx);
y = linspace(0, 1, Ny);
z = linspace(0, 1, Nz);
[X, Y, Z] = ndgrid(x, y, z);
V = 1.5*X + 2*Y + 3*Z + 0.2*(X.^2 + Y.^2 + Z.^2); % strictly increasing
save bigdata.mat V x y z
2. load in model workspace
3. put tic and toc in the initFcn and StopFcn call backs
4. use this very simple LUT
the elapsed time is the same before and after adding this data to the model workspace.
and it takes some time for compilation everytime I run the model.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by