2
$\begingroup$

I have a notebook which has a lot of generated data (which I would rather not regenerate), and the kernel is dead. So, the question is, how do I recover the data in the notebook (I know it is there, since the save file is very, very large, but obbiously %28, or whatever, will not work). I can copy the output cell as LaTeX or MathML [which is not what I want] or convert it to InputForm (which IS what I want, but where does the converted thing go then?)

Anyway, this is a newbie sort of question, but, well...

$\endgroup$
1
  • $\begingroup$ If in output there is somethin you would not evaluate, do not use this. But if there are only simple output cells, try: With[{l = Length[#]}, CreateDocument@ Table[ With[{var = "x" <> ToString[i]}, Composition[ Cell[#, "Input"] &, BoxData, Cases[#, BoxData[x_] :> RowBox[{var, "=", x, ";"}], 1][[1]] &,NotebookRead ]@#[[i]] ], {i, l}] ] &[Cells[EvaluationNotebook[], CellStyle -> "Output"] ] $\endgroup$
    – Kuba
    Commented Oct 1, 2014 at 20:03

1 Answer 1

5
$\begingroup$

So is the scenario that you have some notebook with input cells that look like

data = myfunctionThatGivesALotOfData[...]

which have produced output cells that look like

{9.34648, ... ,7.6569}

and you want to start a new kernel session and get the value of data ?

If that's the case, you can just put your cursor at the beginning of the output cell(in this case {9.34648, ...) and then just type data = and it will automagically convert the output cell into an input cell, and once you evaluate it you'll have your definition of data.

If you want to do this programmatically via something like NotebookGet then that's a bit more involved, but not terrible(I'd suggest starting on the ref page for NotebookGet).

$\endgroup$
4
  • $\begingroup$ Truly, you are wise in the ways of science! $\endgroup$
    – Igor Rivin
    Commented Oct 1, 2014 at 17:55
  • $\begingroup$ Except when I did this (this is in MMA 10.0.1, in case it matters, and then I asked for the value of "data", I got %29. Now, maybe I should reload the notebook, and see what happens?! $\endgroup$
    – Igor Rivin
    Commented Oct 1, 2014 at 17:58
  • $\begingroup$ Or, to make it clearer: if my cursor is inside the "grey" area (where the output is), mathematica does not accept input. If I put it just outside, I get %28 (for whatever reason) as the value. $\endgroup$
    – Igor Rivin
    Commented Oct 1, 2014 at 18:00
  • $\begingroup$ @IgorRivin if the info is stored in one of those gray, large-output boxes, it is properly gone. That's just an input form for %n. To demonstrate this, try: ConstantArray[10000, {1000, 1000}] followed by ToExpression[First@NotebookRead@NextCell[], StandardForm, HoldForm] in the same cell (so that NextCell catches the output from the ConstantArray call). Sorry to disappoint. $\endgroup$
    – b3m2a1
    Commented Dec 14, 2016 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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