Message Boards Message Boards

2
|
9933 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Save expression and load them into another notebook efficiently?

Dear all,

I am seeking for the best method to save long clumsy expressions locally and load them later into another notebook without actually seeing them (not copy-paste).

The expressions will dominantly be used in modules, and since they sometimes occupy a few pages (even after FullSimplify), it would be nice to have them not visible.

I have created an example notebook (see attached), which shows what I would like to express: The “magenta” part refers to the calculation of the expression without assigning any value to the variables. The “green” part relates to the actual numerical calculation, which will be done in another notebook.

So the overall question is: How to save expression efficiently and load/use them in another notebook?

Any help would be greatly appreciated.

Regards,

Markus

Attachments:
POSTED BY: Markus Schmidt
2 Replies

That is great, thanks. I think that is what I was looking for. Markus

POSTED BY: Markus Schmidt

MX (.mx) is Wolfram Language serialized package format developed by Wolfram Research. It stores arbitrary Wolfram Language expressions in a serialized format optimized for fast loading and preserves anything including the options, etc. For example

res = RandomGraph[{15, 35}, VertexSize -> "BetweennessCentrality"]

enter image description here

Save the fale with DumpSave

DumpSave["res.mx", res];

Now relaunch the kernel:

Exit

And reload the file:

<< res.mx

You will not see result but you have the definition of your variable:

res

enter image description here

Keep in mind that MX files cannot be exchanged between different operating systems or versions of the Wolfram System. In this case you can Export compressed string of any expression:

Compress[res]
Export["res.txt", %]

enter image description here

and Import it back intact:

Uncompress[Import["res.txt"]]

enter image description here

I'd recommend careful reading through: How do I save a variable or function definition to a file?

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract