Group Abstract Group Abstract

Message Boards Message Boards

How do I use a Do loop on a Manipulate?

Posted 3 years ago

How do I use Table and Do loop iterators inside Manipulate? Is there a way to use Iterators inside a Manipulate function?

 Do[
  ToExpression[
    "CombinedCartesianPlot\[NumberSign]" <> ToString[Mass] <> 
   "\[NumberSign]" <> ToString[Radius], StandardForm,
    Function[sym, 
     sym = Manipulate[Show[
      {If[a == 1, 
        ToExpression[ 
         "CartesianPlotWith\[NumberSign]" <> ToString[Mass] <> 
          "\[NumberSign]" <> ToString[Radius]], Nothing], 
       If[a == 1, 
        ToExpression[
         "CartesianPlotWithout\[NumberSign]" <> ToString[Mass] <> 
          "\[NumberSign]" <> ToString[Radius]], Nothing]},   
      PlotLabel -> 

       "Positions of With and Without Photophoresis of a particle \
with #InsertRadiusHere#", 
      Frame -> True], {{a, 1, "With"}, {1, 0}}, {{b, 1, 
       "Without"}, {1, 0}}, ControlPlacement -> Top, 
     FrameMargins -> 0, TrackedSymbols :> {a, b}], 
      HoldAll]
    ],
  {Mass, 1, 6}, {Radius, 1, 6}
  ]

The Do Loop Iterators (Mass & Radius) would not be evaluated and are labeled Red instead.

4 Replies

Lance,

You should not be using strings to construct expressions in Mathematica except in unusual cases. In this case you can do what you want directly without any strings. I can't understand what you want the final output to look like unless you describe it or draw a picture, but a simple example of a something related would look like this:

Manipulate[
 Column[Table[
   Show[Plot[a * x^(2 + (b - 1)/10), {x, 0, 3.5}], 
    ListPlot[a*{1, 4, 9}], ImageSize -> Medium], {b, 4}]], {a, 1, 5}]

or a grid like this:

Manipulate[
 Grid[Partition[
   Table[
    Show[Plot[a * x^(2 + (b - 1)/10), {x, 0, 3.5}], 
     ListPlot[a*{1, 4, 9}], ImageSize -> Medium], {b, 4}], 2]], {a, 1,
   5}]

You use Table to create a list of Plots and partition it into a Grid (or use Table with two iterators). The you can use manipulate to alter Parameters that you want to change by hand.

Regards,

Neil

POSTED BY: Neil Singer
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

Oops, realized that I ultimately chose not to use AssignMassRadius, but hopefully you get the idea.

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