Craig
Craig

Reputation: 991

How can a Simulink model discover it's own filename and path?

I would like to display some information about a Simulink model, without first knowing the filename. The information will be displayed in the model itself.

Something similar, mfilename, is available for MATLAB programs. Is there an equivalent for Simulink models?

Upvotes: 3

Views: 7924

Answers (3)

Carl
Carl

Reputation: 31

I think it may be more reliable to get the model parameter in case there is more than one matching model in your path:

model_path = get_param(bdroot, 'FileName');

Upvotes: 3

Craig
Craig

Reputation: 991

Thanks to Edric I found bdroot, which gives the system name. Passing this to which makes Matlab find the model using it's search path.

So the solution is model_path = which (bdroot);

One problem is that if you have shadowed files this method may give the incorrect answer.

Upvotes: 4

Edric
Edric

Reputation: 25160

I think you need gcs http://www.mathworks.com/help/toolbox/simulink/slref/gcs.html

Upvotes: 0

Related Questions