how do you display the current workspace name

53 次查看(过去 30 天)
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 个评论
Cam Salzberger
Cam Salzberger 2017-10-12
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 2017-10-12
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?

请先登录,再进行评论。

回答(3 个)

Image Analyst
Image Analyst 2017-10-12
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 2017-10-12
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 个评论
Cedric
Cedric 2017-10-12
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.

请先登录,再进行评论。


Aniruddha Katre
Aniruddha Katre 2017-10-12
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.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by