MATLAB: Find by command line (.m script) the Source File for a loaded model

modelsource file

Hello, Is it anybody that could help me to find how to read by command line (.m script) the Source File for a loaded model? This model property can be found in the Model Properties, under Main tab in Model information. I cannot use:
info = Simulink.MDLInfo(ModelName);
as I have two distinct projects with identical structure and filenames. I am also changing often between projects and I need to find which model is currently opened. Thanks in advance!

Best Answer

bdroot(gcs) or bdroot(gcb) might be what you need.