Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

A few weeks ago I created a big matrix, and in order not to have to recreate it, I stored it using DumpSave["file.mx", variable]. Now I want to read it back in and so I use <<file.mx. It appears to work fine and to load the file (which takes a few moments because it is 54 MB in size). Now the problem: I have forgotten what I called the matrix, that is, what name variable I used in when I saved it. My generating command is unfortunately not around any more. Is there any way of figuring out what my variable was called or more directly, how to access my data now that it is loaded?

share|improve this question
    
I suggest that you also save the notebook you had been working on, and that you use this same notebook to store and load the DumpSave. That way you can resume your workflow exactly where you left off, and you won't have to remember the name of your variables. –  becko May 11 '13 at 5:50
    
@becko I do actually have the notebook, but I saved a number of things at different times and evidently erased the particular DumpSave that I ended up needing. Your point is well taken: be more careful! –  bill s May 11 '13 at 6:16
    
Related: (2900) –  Mr.Wizard May 11 '13 at 7:55
    
@Mr. Wizard - My problem was actually simpler than in the link, and xsLittlegrass's suggestion of looking at all variables solved it nicely. I did try opening in a text editor, but the file is 54 MB and I wasn't able to spot the right variable name -- presumably it is there somewhere. –  bill s May 11 '13 at 8:02
2  
The real solution here is rm's answer. DumpSave gets suggested much too often on this site when it's really cumbersome, exactly for the reason you describe. Don't use DumpSave unless you really need to. Just use Export instead. –  Szabolcs May 11 '13 at 13:58
show 1 more comment

2 Answers 2

up vote 16 down vote accepted

I think you can use Names["Global`*"] to get the name:

a = RandomReal[{0, 1}, 10];
SetDirectory[$TemporaryDirectory];
DumpSave["1.mx", a];

Quit[]

SetDirectory[$TemporaryDirectory];
<< 1.mx
Names["Global`*"]

(*{"a"}*)
share|improve this answer
    
Hey great! I can now see that my matrix was called uAll. How could I have forgotten that? Thanks xslittlegrass. –  bill s May 11 '13 at 5:31
add comment

If you use Import/Export to load/save .mx files, instead of DumpSave, then the variable does not get embedded in the file, and you can assign it to any variable of choice in the new session.

x = RandomReal[1, {100, 100}];
Export["~/tmp.mx", x];
y = Import["~/tmp.mx"];
x == y
(* True *)
share|improve this answer
2  
+1 In many situations this can be a more organized way to do it. –  becko May 11 '13 at 16:48
    
@rm -rf I'm torn... I want to accept both answers: xslittlegrass's because it solves my immediate problem, and yours because it's a better way to work, which I will follow in the future. –  bill s May 12 '13 at 14:52
1  
@bill Since you were apparently not familiar with this method you might also learn something form this summary I put together: mathematica.stackexchange.com/a/2008/121 –  Mr.Wizard May 12 '13 at 18:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.