Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a contrived example, but it gets the point across. I am looking to use the following as inputs:

a = {10, 11};
b = {5, 7};
MakeCD[x_] := {{x, 2 x}, {3 x, 4 x}};

to function that takes a list of sublists. ListPlot is a suitable example of the function.

Using 1 as the argument to MakeCD, MakeCD returns: {{1, 2}, {3, 4}}

I am looking to supply {{10, 11}, {5, 7}, {1, 2}, {3, 4}} to ListPlot

I can achieve this with the following:

{c, d} = MakeCD[1];
{a, b, c, d}

Also with:

Join[{a}, {b}, MakeCD[1]]

I am sure there is a better way to do this, but I have not yet stumbled upon it yet.

share|improve this question
Something like Flatten[{MakeCD[1], MakeCD[10]}, 1] ? – b.gatessucks Aug 30 '13 at 20:43
@b.gatessucks unfortunate contrived example that MakeCD can generate a,b,c,d. I changes that. – mmorris Aug 30 '13 at 21:33
up vote 3 down vote accepted

Second try:

From the comments I believe you are looking for Sequence:

{a, b, Sequence @@ MakeCD[1]}
{{10, 11}, {5, 7}, {1, 2}, {3, 4}}

You can include this in the definition of MakeCD, or an auxiliary function, to streamline this:

MakeCD2[x_] := Sequence[{x, 2 x}, {3 x, 4 x}];

{a, b, MakeCD2[1]}
{{10, 11}, {5, 7}, {1, 2}, {3, 4}}

You can also use SlotSequence to perform a similar action:

{a, b, ##}& @@ MakeCD[1]
{{10, 11}, {5, 7}, {1, 2}, {3, 4}}

Or more in line with your application:

plotfunction[{a, b, ##}, plotoptions] & @@ MakeCD[1]
plotfunction[{{10, 11}, {5, 7}, {1, 2}, {3, 4}}, plotoptions]

For an advanced method that will be useful with held expressions see:
Injecting a sequence of expressions into a held expression

share|improve this answer
I have a variable number of series of date data to be plotted by DateListPlot. In my example, I have two represented by a & b. There could be any number of series of date data (1-5+). In addition to the series data, I will also always have two additional series of date date that are generated by a function. In my example, that is represented by MakeCD[]. The problem is that any function that returns multiple values, returns a list of the values, in my case series of date data. I was hoping for a way to remove the outer list and just supply the two sublists to DateListPlot – mmorris Aug 30 '13 at 22:24
i.e. DateListPlot[{a,b,x,y,z, Delistify[MakeCD[1]] Obviously Delistify[] does not exist, but the result would have been DateListPlot[{a,b,x,y,z,{1,2},{3,4}] And yes that would not have plotted since {1,2} should have been something like {{{2013, 8, 27}, 42}, {{2013, 8, 28}, 40}}. Just trying to save space, but probably cause more confusion. – mmorris Aug 30 '13 at 22:31
@mmorris Oh! I think you're just looking for Sequence. Update imminent. – Mr.Wizard Aug 30 '13 at 22:42
@mmorris Don't miss my addition regarding SlotSequence -- it's the method I use most often in cases like this. – Mr.Wizard Aug 30 '13 at 22:48
I understand Sequence, wrapping my head around SlotSequence. Thanks – mmorris Aug 30 '13 at 22:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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