{"id":82,"date":"2010-02-18T05:55:30","date_gmt":"2010-02-18T05:55:30","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2010\/02\/18\/is-that-model-already-open\/"},"modified":"2018-01-08T15:54:25","modified_gmt":"2018-01-08T20:54:25","slug":"is-that-model-already-open","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2010\/02\/18\/is-that-model-already-open\/","title":{"rendered":"Is that model already open?"},"content":{"rendered":"<p>I was just clicking through my vast inbox of unread e-mail, and saw a MATLAB Central news reader alert.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2010Q1\/newsReaderAlerts.png\" alt=\"MATLAB Central News Reader alerts\" \/><\/p>\r\n\r\n<p>I quickly scanned the message and then clicked on the link to <a>view the thread on MATLAB Central<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2010Q1\/simulink_open_systemThread.png\" alt=\"Simulink open_system thread on the MATLAB Central News Reader\" \/><\/p>\r\n\r\n<p>Regular contributor <a>Ben Harper<\/a> asked the question:\r\n\r\n<blockquote>i can open a simulink file with \"open_system\" command.\r\n\r\nI want to see if the simulink model is opened?<br>\r\nhow can i check whether the mdl file is opened or not?<br>\r\n<br>\r\nthank you. <\/blockquote><br>\r\n<\/p>\r\n\r\n<p>His first response came from <a>Jason Retik<\/a>:\r\n\r\n<blockquote>openModels = find_system('SearchDepth', 0)<br>\r\n<br>\r\nopenModels will be a cell array of all the currently opened models. You can \r\nuse the STRCMP function on openModels to check whether a particular model is \r\nopen.<\/blockquote><br>\r\n<\/p>\r\n\r\n<p>This has all the ingredients to get Ben up and running, but <a>Gavin Walker<\/a> also replied:<br>\r\n<br>\r\n<blockquote>Try \"bdIsLoaded\"<br>\r\n<br>\r\nGavin<\/blockquote><br>\r\n<\/p>\r\n\r\n<p>While I thought a function like this existed, it wasn't at the top of my mind.  <tt><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/simulink\/slref\/bdisloaded.html\">bdIsLoaded<\/a><\/tt> returns true for models that are <em>in memory<\/em>.  The function takes a model name as a string, or a cell array of model names as its input.<\/p>\r\n\r\n<p>If you <tt>edit bdIsLoaded.m<\/tt>, you will see that it includes the exact <tt>find_system<\/tt> call Jason suggested, plus a little code to check if your specific model is loaded.<\/p>\r\n\r\n<p>Is that the answer?<\/p>\r\n\r\n<p>Going back to the original question, I want to further improve this answer.  The original question was about the use of <tt>open_system<\/tt>, which is different than <tt>load_system<\/tt>.  Block diagrams can be loaded, but not visible to the user.  I think Ben's original question is whether a particular model is visible or not, so here is my answer:<\/p>\r\n\r\n<p>First check to see if the model is loaded, and if it is, use get_param to check the Shown property.  Here is an example:\r\n\r\n<code>>> load_system('vdp')<br>\r\n>> bdIsLoaded('vdp')<br>\r\nans =<br>\r\n     1<br>\r\n>> get_param('vdp','Shown')<br>\r\nans =<br>\r\noff<br>\r\n>> open_system('vdp')<br>\r\n>> get_param('vdp','Shown')<br>\r\nans =<br>\r\non<\/code><br>\r\n<br>\r\nThe model is only visible if Shown==on.<\/p>\r\n\r\n<p><strong>Where do you get your answers?<\/strong><\/p>\r\nHow about <a href=\"https:\/\/www.mathworks.com\/support\/\">technical support<\/a>?  Leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=82&#comment\">comment here<\/a> and tell us about it.<\/p>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>I was just clicking through my vast inbox of unread e-mail, and saw a MATLAB Central news reader alert.\r\n\r\n\r\n\r\nI quickly scanned the message and then clicked on the link to view the thread on MATLAB... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2010\/02\/18\/is-that-model-already-open\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,34],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/82"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":6998,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/82\/revisions\/6998"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}