0
$\begingroup$

I have a number of lists, labed s1,s2,s3,..,s100. And si(i=1,2,...,100) has different lengths and different coordinates. For example, the fist three lists are like

s1 = {{1, 1}, {1, 2}, {1, 3}, {1, 4}};
s2 = {{2, 1}, {2, 2}, {2, 3}};
s3 = {{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}};

What I want to obtain is

{{1, 1}, {1, 2}, {1, 3}, {1, 4},{2, 1}, {2, 2}, {2, 3},{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}};

In short, I want to make these coordinates in si(i=1,2,...,100) together, leading to one list. I know 'Join', it make two lists together. If I use 'Do', 'For' and so on, how to achieve it? Thank you.

$\endgroup$

closed as off-topic by m_goldberg, Henrik Schumacher, José Antonio Díaz Navas, yohbs, Sektor Apr 12 '18 at 18:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Henrik Schumacher, José Antonio Díaz Navas, yohbs, Sektor
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Why did you not try Join[s1, s2, s3]? $\endgroup$ – J. M. will be back soon Apr 11 '18 at 3:08
  • $\begingroup$ Also Flatten[{s1, s2, s3}, 1] $\endgroup$ – Bob Hanlon Apr 11 '18 at 3:21
  • $\begingroup$ @J. M. needs help If the lists are too many, we can not use Join[s1,s2,s3,s3,..,s100],.But I have tried loop commands('Do', 'For'), I still not obtain it. $\endgroup$ – kuzb Apr 11 '18 at 3:23
  • $\begingroup$ @Bob Hanlon Thank you $\endgroup$ – kuzb Apr 11 '18 at 3:24
  • 6
    $\begingroup$ If you have to keep 100 variables around, you're likely doing something wrong. $\endgroup$ – J. M. will be back soon Apr 11 '18 at 5:45
4
$\begingroup$
s1 = {{1, 1}, {1, 2}, {1, 3}, {1, 4}};
s2 = {{2, 1}, {2, 2}, {2, 3}};
s3 = {{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}};
numberOfLists = 3;
Flatten[Join[Table[ToExpression["s" <> ToString[i]],{i, numberOfLists}]], 1]

Mathematica graphics

change numberOfLists to 100 or 1000 as needed. But I do not think it is a good idea to have so many variables s1, s2 etc... You could design your data struct to avoid this. Use 3D matrix for example. Each page of the matrix is your s. This way you can iterate over pages of one variable of type 3D matrix instead of 100's of separate named variables.

$\endgroup$

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