Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:10:04+00:00 2026-06-13T10:10:04+00:00

I’m trying to turn some code written in Matlab into a standalone, compiled Matlab

  • 0

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 name_of_folder.name_of_function. 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).

Then I saw the import 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

function foo(var1, var2, ..., packagename)
  eval(sprintf('import %s.*', packagename));
  ...
  bar1(var1, var2);
  ...
  bar2(var2);
  ...

then I’m hoping bar1 and bar2 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.

So, what is the scope of an import statement? Alternatively, is there another way to deal with this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:10:05+00:00Added an answer on June 13, 2026 at 10:10 am

    I wrote some test code to try it out for myself, and indeed, the import statement is limited to only the function that called it, which makes sense but I guess my hope clouded my judgement. For the record, I wrote the following short functions to test it:

    function package_test(package_name)
      eval(sprintf('import %s.*;', package_name));
    
      test_function();
    end
    

     

    function test_function()
      nested_function()
    end
    

    and then put

    function nested_function()
      disp('I\'m in the original folder :(');
    end
    

    in the same folder as the first two functions, and

    function nested_function()
      disp('I\'m in the package! :)');
    end
    

    in a folder named +trial. Of course, when I ran package_test('trial'), I saw “I’m in the original folder :(” displayed in the window, while trial.nested_function() gave me the string I hoped to see.

    Furthermore, the eval function poses a problem to the compiler, and replacing it with import(sprintf('%s.*', package_name)); doesn’t seem to help either. So it looks like I’m back to duplicating files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.