I want to make a sequence like follows


The above r[i] represents coordinates which I have to type in manually one by one. So I make such a sequence to make the typing easier and more confortable. (even without having to type the =, I am so lazy, I admit). If the problem involve n coordinate, I just generate a sequence of length n. So I naively write as follows

Table[r[i]= ,{i,1,n}]//TableForm

But with = there, I can't make such a list. So how could I generate a sequence of such incomplete expressions (like the above expressions, the = has no right side, this makes Mathematica can't table it)?

  • 8
    $\begingroup$ This is not a good way to write software. $\endgroup$
    – Nasser
    Jan 4, 2013 at 3:16
  • $\begingroup$ @Nasser hey! your comment above should be kept in some distinguished place! $\endgroup$ Jan 4, 2013 at 4:52
  • $\begingroup$ @Nasser Hi! Nasser. Thank you for your suggestion. But you leave a sentence without any further explanation. And I don't know why my way of typing input is not proper. The "r[i]" represents coordinate, when doing a specific calculation, I have to input initial coordinate manually one by one according to real situations. I can't find a better way to do it. Could you suggest a better way for me? $\endgroup$
    – matheorem
    Jan 4, 2013 at 6:57
  • $\begingroup$ It sounds like you're building a data entry user interface. There might be a more natural way to do this, but it would help to describe more what you're doing. E.g. is the size of the list, n, known ahead of time or can it vary? $\endgroup$
    – Joel Klein
    Jan 4, 2013 at 7:12
  • $\begingroup$ @JoelKlein n is also dependant on specific question. But it won't vary within the same question. What I want to do is actually a plot on a zigzag line, and r[i] represent the turning point $\endgroup$
    – matheorem
    Jan 4, 2013 at 7:21

3 Answers 3


I'm not sure what you're trying to do here and most probably Nasser's admonition rings true, but perhaps you want something like this?:

 CellPrint @
  Cell[BoxData[RowBox[{RowBox[{"r", "[", i, "]"}], "="}]], "Input"],
 {i, 5}

Alternatively you might make use of \[Placeholder] and Defer:

Do[CellPrint @ ExpressionCell[Defer[r[#] = \[Placeholder]], "Input"] & @ i, {i, 5}]

Function (short form &) is needed to get the value inside Defer as the latter has a Hold attribute. See Function in Table for more. Array as used below is more practical in this specific case, but I wanted to demonstrate using Do or Table as well in case your indexes are not the natural numbers.

Better still with all of these inputs in a single Cell:

    Array[ToBoxes @ Defer[r[#] = \[Placeholder]] &, 5] ~Riffle~ "\n"
] // CellPrint

Mathematica graphics

Now the advantage of using \[Placeholder] becomes clear: you can use Tab to move between input fields.

You may not want to use this kind of input method at all. You can make assignments like this:

{r[1], r[2], r[3], r[4], r[5]} = {0.0, 0.2, 0.4, 0.6, 0.8}

You could get the left-hand side list with simply Array[r, 5] (assuming no prior assignments).

Depending on your application you could also store one list (array):

s = {0.0, 0.2, 0.4, 0.6, 0.8};

Then use Part to access elements:

{s[[2]], s[[5]]}
{0.2, 0.8}

Perhaps you want each value on a separate line. You can use Ctrl+Enter to create an ad hoc table:

Mathematica graphics

When evaluated the data looks like this:

{{0.}, {0.2}, {0.4}, {0.6}, {0.8}}

You could use Join or Flatten to get back to the simple list form used with s.

You could also make assignments for a given list of values as m_goldberg shows.

  • $\begingroup$ Yeah! That's exactly what I want. I have more questions. First, why there is ToString before i ? I found that it also works without ToString. Second, why there is two RowBox? I found that with only one RowBox, that is to write like RowBox[{"r", "[", i, "]", "="}], will give result with a colored left bracket. Though the colored left brackets seems harmless, because I can set values normally. But I still curious about it. And finally both you and Nasser point it out that my way of input is not good. I leave a message for Nasser, would you take a look at it? $\endgroup$
    – matheorem
    Jan 4, 2013 at 6:57
  • $\begingroup$ @user I was in a hurry last night. You're right, ToString is unnecessary here. Also, I got the Box structure quickly by typing r[1]= in a cell and using Cell > Show Expression (Ctrl+Shift+E on Windows), which is typically the simplest way to get the underlying Box form that Mathematica (or more specifically the FrontEnd) uses. See this question for another. I'll add a couple of things to my answer that I hope you'll find useful or informative. $\endgroup$
    – Mr.Wizard
    Jan 4, 2013 at 15:08
  • $\begingroup$ Hi,Wizard. Sorry for this late comment. Thank you very much for your elabrate and perfect answer. From you, I learned the cell structure. $\endgroup$
    – matheorem
    Jan 31, 2013 at 4:18
  • $\begingroup$ @user15964 You're welcome, and thanks for the Accept. $\endgroup$
    – Mr.Wizard
    Jan 31, 2013 at 7:32

I'm guessing the OP is looking a way to generate a number of indexed assignments from a list of data elements. If so, then maybe something like the following will work for the OP:

Clear[data, r];
data = RandomInteger[{0, 99}, 5];
MapIndexed[(r[#2[[1]]] = #) &, data];




Here is a simplistic approach, I'd be interested in how it does or does not meet your requirements:



{1, 5, 2}

If you wanted a more structured input format, try setting the value of r equal to the result of the first part of an input table (via menus, Insert->Table/Matrix->New ) which gives you something like this:

Mathematica graphics

And then parts of r can be accessed as per the above example with r[[n]].

  • $\begingroup$ damm I was just writing very same answer. Yes, the OP should just use a simple list $\endgroup$
    – Ajasja
    Jan 4, 2013 at 10:07
  • $\begingroup$ @Ajasja It certainly seems a possible solution. Sorry, I know that can be frustrating :( $\endgroup$ Jan 4, 2013 at 10:11
  • $\begingroup$ @image_doctor Thank you, Image_doctor! I know what you mean, ,I actually want the input process more intuitive. I have edited my question to make myself clear. $\endgroup$
    – matheorem
    Jan 4, 2013 at 11:03
  • $\begingroup$ @image_doctor No, no, I don't mean this as a serious comment (just forgot to end with a smiley:) $\endgroup$
    – Ajasja
    Jan 4, 2013 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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