4
$\begingroup$

I have a lot of data sets. I want to plot all of them and export some of them to file (or print them as in example below) by clicking buttons generated next to plots.

(*Create list of 5 random data sets*)
datalist = RandomInteger[10, {5, 20}];

(*Plot all data sets and create buttons to print raw data*)
Table[{ListPlot[data], Button["Print data", Print[data]]}, {data, datalist}]//Grid

My approach is not working, as the action of the button is executed outside of the scope of 'Table' function. How can I procedurally generate distinct buttons binded to different elements from list?

$\endgroup$
6
$\begingroup$

That's a typical use of With[]:

(*Create list of 5 random data sets*)
datalist = RandomInteger[10, {5, 20}];

(*Plot all data sets and create buttons to print raw data*)
Table[
  {ListPlot[data],
   With[{data00=data},Button["Print data",Print[data00]]]},
  {data, datalist}] // 
Grid  

data00=data ... Print[data00] could perfectly be replaced by data=data ... Print[data]

enter image description here

When you push a button, then the data are printed :

{5,4,3,9,10,9,2,9,4,5,9,6,8,5,0,9,4,9,6,4}

$\endgroup$
1
$\begingroup$
Grid[{ListPlot[#], Button["Print", Print[#]]} & /@ datalist]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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