0

I have several Simulink models in different folders and I need to load all of them in the Matlab, one after the other. To this goal, I have used the following code.

addpath(genpath(strcat('\ConfigsSimulinkModels')));

init; %Initialize variables
for i=1:24
    correctModel=strcat('ConfigsSimulinkModels/C0000',int2str(i),'/TanksModel0000',int2str(i));
    load_system(correctModel);
    set_param(correctModel,'StopTime',300);            
    close_system(correctModel);

end

When I run the code, it shows the following error.

Invalid Simulink object name: ConfigsSimulinkModels/C00001/TanksModel00001

I am pretty sure that it happens because the models are in the folders and subfolders. Is there any way to load a Simulink model into the memory in Matlab while the models are in other folders or subfolders? By the way, I cannot put the models in the same folder.

zari
  • 1,709
  • 1
  • 12
  • 18
  • 1
    You are already adding all subfolders to your path, so you should be able to load the models without their full path just by the model name. These names should be unique on your path anyway to avoid shadowing. – Wolfie Feb 18 '20 at 08:27
  • @Wolfie Unfortunately, it does not recognize the models if I remove the path from the name, though the names are uniques. – zari Feb 19 '20 at 15:47
  • Could you use `oldFolder = cd;` before the loop, then `cd('myPath\Whatever\')` before each model to go to the right folder, then load the model, then after the loop do `cd(oldFolder)` to reset your current path? – Wolfie Feb 19 '20 at 15:59

0 Answers0