title: What is the scope of Matlab's import function?
body: <p>I'm trying to turn some code written in Matlab into a standalone, compiled Matlab application. However, after getting some odd errors, I realized that the code makes a lot of use of adding and removing from the path to get around the fact that there are several functions with the same name (but different results/calculations) used multiple times. Looking around, I discovered that you can turn a folder into a package by putting a "+" in front of its name, and going through and making sure the functions in that package refer to each other using <code>name_of_folder.name_of_function</code>. This solves the namespace problem, but it potentially creates a lot of work, in that I now have to go through and prepend the correct package to each function call (and I may still end up having to duplicate a lot of files).</p>
  
  <p>Then I saw the <code>import</code> function, and I'm hoping that'll save me some time. I think I can pass the package I want to one or two particular functions, have those function import the package, and then things will work the way I want--if the functions that those functions call fall into the scope of that import statement. E.g, if I set something up like</p>
  
  <pre><code>function foo(var1, var2, ..., packagename)
    eval(sprintf('import %s.*', packagename));
    ...
    bar1(var1, var2);
    ...
    bar2(var2);
    ...
  </code></pre>
  
  <p>then I'm hoping <code>bar1</code> and <code>bar2</code> will use the package imported with the import statement. The documentation says that import statements in conditionals and functions are limited to that block of code, but I don't know if "that block of code" means that text only, or "that block of code" being the code and everything that evaluates as a result. I have a feeling it's the former, but I figured I'd ask in the hopes that it is the latter. </p>
  
  <p>So, what is the scope of an import statement? Alternatively, is there another way to deal with this problem?</p>