MATLAB: How to programmatically call “exampleMo​del(…,’c​ompile’)” using a variable for the model name

compilemodelsmultipleprogramaticallysimulink

How can I programmatically call "exampleModel([],[],[],'compile')" using a variable for my model name?

Best Answer

This is possible by doing the following:
1) Store the model name to a variable:
>> myModelVar = 'exampleModel';
2) Call the model function using the "eval" command as follows:
>> eval([myModelVar, '([], [], [], ''compile'');']);
This same method can be applied to a cell array of model names as well, if there are multiple models to compile.