3
$\begingroup$

I would like to have 4 output fields for something like the following:

Manipulate[
n*x
n/x
n + x
n - x,
{n, 1, 10}, {x, 1, 10}, ControlType -> InputField]

but this just outputs all 4 calculations combined.

$\endgroup$
  • 3
    $\begingroup$ Try something like this: Manipulate[ Row[{n*x, "," , n/x, ",", n + x ",", n - x}], {n, 1, 10}, {x, 1, 10}, ControlType -> InputField] $\endgroup$ – Artes Dec 15 '13 at 18:58
  • $\begingroup$ Brilliant - thank you :) $\endgroup$ – martin Dec 15 '13 at 19:01
  • $\begingroup$ Although this question arises from a simple mistake, I recommend that it not be closed because this is common problem for beginners, and the question and its answer is likely to help future visitors with a similar problem. $\endgroup$ – m_goldberg Dec 15 '13 at 19:33
  • 1
    $\begingroup$ @m_goldberg but then the title should be improved. Perhaps: "manipulate with multiple outputs"? Of course the main problem here is not Manipulate, but CompoundExpression (and the fact that it is not needed in top level notebook cells) $\endgroup$ – Ajasja Dec 15 '13 at 22:19
  • $\begingroup$ Related: Multiple output cells. One of the answers contains an answer to this question. $\endgroup$ – Michael E2 Dec 15 '13 at 22:52
6
$\begingroup$

As mentioned in the comment by Artes, you can use Row, although you don't need to put in the "," individually. Row takes a spacing element as its second argument.

Manipulate[Row[{n*x, n/x, n + x, n - x}, ", "],
  {n, 1, 10},
  {x, 1, 10},
  ControlType -> InputField]

manip.png

You can get much fancier, of course. For example:

Manipulate[Column[{
   Row[{"n*x = ", n*x}],
   Row[{"n/x = ", n/x,}],
   Row[{"n + x = ", n + x}],
   Row[{"n - x = ", n - x}]}],
 {n, 1, 10},
 {x, 1, 10}, ControlType -> InputField]

manip2.png

For the ultimate in layout control, take a look at Grid.

$\endgroup$
  • $\begingroup$ Thank you - this is really helpful :) $\endgroup$ – martin Dec 15 '13 at 19:23

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.