I am doing a number of calculations and I wish to add the results to a list. I would then like to select some of the results using check boxes and plot those results together. The length of the list of results will change as more results are added. I can't see how to link the Checkbox to showing the results. Here is a minimum working example.
The first module gives a name to the results. The second module assembles the results and adds a Checkbox. Here is where I can't think of a way of connecting the checkbox to show or not show the result. Finally there is a button to clear the list of results.
ClearAll[saveFittedResults];
saveFittedResults[] := DynamicModule[{name},
Row[{"Output Name? ",
InputField[
Dynamic[name, (name = #;
AppendTo[allResults, {name, RandomReal[{0, 1}, 2]}];
numOfResults = numOfResults + 1) &]],
Dynamic[name]}]
];
ClearAll[assembleResults];
assembleResults[] := DynamicModule[{a},
Column[{
Dynamic@
Column[Table[{Checkbox[Dynamic[]], allResults[[n, 1]]}, {n,
Length[allResults]}]],
Dynamic@
ListPlot[allResults[[All, 2]][[selectedResults]],
PlotRange -> {{0, 1}, {0, 1}}, Frame -> True,
PlotStyle -> {Red}]
}]
];
ClearAll[delButton];
delButton[] := Row[{Button["Delete all results",
ClearAll[allResults, numOfResults, selectedResults];
allResults = {};
selectedResults = {};
numOfResults = 0],
" Number of results = ", Dynamic[numOfResults]}]
If the modules are executed then we get
delButton[]
saveFittedResults[]
assembleResults[]
Here I have added 5 tests
If I type
selectedResults = {1, 2, 4}
data appears in the plot so that part of the code is working.
How do I do the really difficult bit of connecting each Checkbox to put a value in selectedResults
? or is there a better way of doing this?
Thanks