Do two instances of MATLAB share a workspace?

19 views (last 30 days)
I have a permutation test running in one MATLAB window, and I want to open a new instance of MATLAB to run the same test but with different data (after pausing the first one since otherwise it gives me the error "Cannot open the Import Wizard on a file while the Import Wizard is open"). Then I try to load my data to the workspace of MATLAB instance #2 by simply double clicking the data file in a folder somewhere in my Documents, the Import Wizard opens, and there I go to rename my variable name. This renaming is important since the permutation test code I will run depends on it as input. However, since the script takes in this data under the same variable name for both instances, I get a warning saying that a variable with that name already exists in the MATLAB Workspace, Are you sure you want to overwrite it? I definitely do NOT want to override it.
I need the two workspaces for each instance of MATLAB to remain completely independent of eachother because the same script will generate results under the same variable names, but the code running in one instance should have no access to the code/workspace running in the other instance. Ideally, I want to run both at the same time, but I am also okay with pausing one while running the other. But the first instance has been running for days (and has many days to go) and I do not want to have to start over, nor do I want to have data overwritten by this second instance and leave me with completely incorrect numbers in my resulting matrices. How can I do this?
When I try to import data, it always goes to the first instance's workspace/command window, and gives me the following error: 857 Error using assignin Attempt to add "<variable name>" to a static workspace. See Variables in Nested and Anonymous Functions.
Error in unimportant/finish (line 857) assignin('caller',newVariableNames{j},newData.(newVariableNames{j}));
Thank you in advance for your help
  2 Comments
Stephen23
Stephen23 on 15 Aug 2018
Edited: Stephen23 on 15 Aug 2018
Error using assignin Attempt to add_ "<variable name>" _to a static workspace. See Variables in Nested and Anonymous Functions
You cannot magically add variables to workspaces of nested functions, as the MATLAB documentation clearly states:
Nor should you ever magically make variables appear in any workspaces, unless you want to force yourself into writing slow, complex, buggy code:
Shanty Kamal
Shanty Kamal on 15 Aug 2018
My intention is not to magically add variables to workspaces of nested functions, but to load data under a specific variable name in the base workspace of my 2nd instance of MATLAB while NOT at all interacting with the variables inside the workspaces (base or any other workspace on the function call stack) contained in the 1st instance of MATLAB.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 15 Aug 2018
Edited: James Tursa on 15 Aug 2018
Just open up two different instances of MATLAB ... they will be two separate processes with two completely independent workspaces. The issue you will have to deal with is if both instances try to access the same file at the same time ... then you will have a clash.
  1 Comment
Mark Magdaleno
Mark Magdaleno on 16 Oct 2020
Will there exist 2 separate editor histories, command histories etc?

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!