how do you display the current workspace name

54 views (last 30 days)
kmbxrf
kmbxrf on 12 Oct 2017
Commented: Cedric on 12 Oct 2017
Is there a way to identify the current workspace (the name of the .mat file) without having to load again? I thought it would be easy to find but . . . . I've looked in preferences but don't see what I'm looking for. Did I miss it?
  2 Comments
Cam Salzberger
Cam Salzberger on 12 Oct 2017
What does a MAT file have to do with workspaces? You can save variables present in workspaces to MAT files, and you can name them whatever you want, but that doesn't make any MAT file the "current workspace".
The only thing that I can think of is that you have a bunch of MAT files. When you load one to whatever workspace you're in, you'd like to be able to write back to the same MAT file with whatever changes you've made. Is that an accurate summation?
kmbxrf
kmbxrf on 12 Oct 2017
I have 2 mat files with same variables for 2 different experiments. Let's say I believe I have the correct one in the workspace but for whatever reason I'm not sure. how do I determine which file is loaded?

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 12 Oct 2017
Each function has it's own workspace. Use dbstack() to find out which function (i.e. which workspace) you're in.

Cam Salzberger
Cam Salzberger on 12 Oct 2017
Thanks for clarifying. Unfortunately, in the situation as you describe it, there's no easy programmatic way to determine which you have loaded. If you haven't modified the variables, you could load each of the MAT files into a structure:
S = load('mymat.mat');
then compare the values of your workspace variables to those in the structure and see which file matches.
If you're willing to do it interactively, you could just go back through your Command History, and see which file was loaded. Even if you double-click a file, the load command will be run in the Command Window, so it should show in your history.
If you're looking to make a workflow around this, though, you could ease the pain with a little planning. I'd suggest making a separate script you can call to save a workspace. In that function, check if "filename" already exists in the workspace. If so, use it to save the file. If not, select a new filename to save to and save that variable with the filename in it. That way, any variables you load from MAT files in the future will already tell you where they came from and where to save to.
-Cam
  1 Comment
Cedric
Cedric on 12 Oct 2017
Extending on this answer, I'd propose that you load a file, save a timestamp and/or a version number into another variable, and save both into a new MAT-File. You do this for the other file as well, and the next time you load a MAT-File, it comes with the version/timestamp.

Sign in to comment.


Aniruddha Katre
Aniruddha Katre on 12 Oct 2017
One option is to save the variables currently in your workspace to a MAT-file with a different name than the one you loaded into memory, and then use the visdiff function to check the difference between the two files.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!