Workspace definition of "a variable" doesn't match this m-scripts definition
3 次查看(过去 30 天)
显示 更早的评论
I got an error message: Error executing "PreSimFcn" on Simulation input object. Workspace definition of "EngineeringModel" doesn't match this m-scripts definition.
I set up a for-loop to run simulations with a Simulink/State flow model. It completed loop 1 simulation successfully. When moving to loop 2, I got this error.
For example, in the entry point of the m-script file. it looks like:
clear;
close all;
clc;
cycles = [1 2 3 4 5 6];
numOfCycles = numel(cycles);
numOfWorkers = 3;
numOfBatch = ceil(numOfCycles/numOfWorkers);
for ii =1:numOfBatch
startII = (ii-1)*numOfWorkers+1;
endII = ii*numOfWorkers;
endII = min(endII,numOfCycles);
batchCycles = cycles(startII):cycles(endII);
myTest = myconfig_batch(batchCycles);
%% Select control option
myTest.Runner.NumWorkers = numOfWorkers;
myTest.runAnalysis; % (1) opens simulation manager and run the batch simulations with the Simulink model
clearvars -except cycles numOfCycles numOfWorkers numOfBatch ii
close all;
clc;
end
The first three cycles are completed succefully; but the second three cycles failed and showed the error message above.
I added clearvars; close all in the for-loop and I hope they can clean up the workspace before new batch is launched.
Below is my observation. If I set 3 cycles instead of 6, I can run and complete the three cycles. Then I changed the cycles to {4 5 6] and restarted the script without closing the Matlab, it still completed the three cycles {4 5 6] successfully.
It looks like Matlab doesn't clean up its workspace in for-loop as I expected. There are still something in the workspace that made "EngineeringModel" doesn't match for loop 2.
My question is: how to clean up everything in the workspace except the few variables by using Matlab script as if the m-script restarts?
0 个评论
采纳的回答
Yuvraj Singh
2023-1-12
Hi Rui,
I understand you are using a loop to simulate some Simulink/Stateflow model, and you encounter error in the second iteration of the loop.
I noticed error states "EngineeringModel" definition doesn’t match the m-scripts definitions. “EngineeringModel" definition is not a variable.
‘clearvars’ removes all variables from currently active workspace. It doesn’t clear any functions, classes or MEX functions.
Depending upon your case you might have to clear functions, classes or MEX functions. ‘clear’ provides options for the same. Please refer to the documentation mentioned below for more details.
I hope it helps you.
-Yuvraj
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!