Workspace definition of "a variable" doesn't match this m-scripts definition
이전 댓글 표시
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개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!