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.

I want Mathematica to excute the first action inside the Button fully before executing the second action. In particular, look at the following plot which I want to Export to a pdf.

Manipulate[myFigure=Show[Plot[x^2+a,{x,-1,1},PlotRange->{-1,4}]],{{a,2,"a"},-1,3},Button["Export a=0",{a=0,Export["Figure1.pdf",myFigure];}],Button["Export a=1",{a=1,Export["Figure2.pdf",myFigure];}]]

If I click Export, Mathematica seems to Export the plot before Updating the Manipulate to the new value for 'a'. However, I obviously want it to change to the new 'a' first, showing the new plot, and then Export this plot to a pdf.

Any thoughts on how to make Manipulate Dynamically Update itself before the Export? Or other solutions?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This works (at least for me):

Manipulate[
 myFigure = Dynamic@Plot[x^2 + a, {x, -1, 1}, PlotRange -> {-1, 4}],
 Column[{
   Slider[Dynamic@a, {-1, 3, 1}],
   Button["Export a=0", {a = 0; Export["Figure1.pdf", myFigure]}],
   Button["Export a=1", {a = 1; Export["Figure2.pdf", myFigure]}]
   }]
 ]
share|improve this answer
    
Thanks, works for me too. Kinda weird, as the whole point of having an expression inside a Manipulate is that the 'Dynamic@' is implied... But ok, it works. –  LBogaardt May 30 at 15:54
    
Actually, is there a way of Exporting the plot without having to name it? I think the order of the sequence is 1. change 'a', 2. Export, 3. give plot name. The 'Dynamic@' you proposed simply changes the order, with the naming as a 2nd step. By skipping the naming, and exporting the plot directly, the problem could also be solved. As in: Manipulate[Show[Plot[x^2+a,{x,-1,1},PlotRange->{-1,4}]],{{a,2,"a"},-1,3},Button[‌​"Export a=0",{a=0,Export["Figure1.pdf",this.Manipulate];}],Button["Export a=1",{a=1,Export["Figure2.pdf",this.Manipulate];}]] –  LBogaardt May 30 at 16:25
    
this.Manipulate doesn't exist in Mathemarica. –  eldo May 30 at 16:32
    
Yeah, obviously :P I was asking if a similar functionality exists. –  LBogaardt May 30 at 16:44
    
@LBogaardt - a similar functionality doesn't exist. –  eldo May 30 at 19:06

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.