2
$\begingroup$

I would like to make a ListLinePlot using these lists:

distance = {0, 5, 25, 45, 65, 85, 105, 125, 145, 150};
trial1 = {0, 0.14, .49, 0.94, 1.39, 1.85, 2.43, 3.08, 3.61, 4.31};

and I would like to get something that looks like this:

{{0, 0}, {5, 0.14}, {25, 0.49}, ... ,{150, 4.76}}

Is there a function or efficient, convenient method I can employ to quickly combine the two lists and form a list shown above instead of painstakingly and inefficiently creating an entirely new list?

For those of you confused about my uneven lists above, I cleaned it up after many many months.

$\endgroup$

closed as off-topic by ciao, MarcoB, m_goldberg, ilian, Bob Hanlon Aug 30 '15 at 17:17

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." – ciao, MarcoB, m_goldberg, ilian, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    $\begingroup$ Look up Transpose[]. $\endgroup$ – J. M. is away Aug 30 '15 at 5:34
  • 2
    $\begingroup$ Your lists don't have the same length. $\endgroup$ – march Aug 30 '15 at 6:28
  • 3
    $\begingroup$ You can do it in this way: Thread@{distance, trial1}. Please obey the hint from @march! $\endgroup$ – user31001 Aug 30 '15 at 9:09
6
$\begingroup$

This problem can be solved with a one-liner.

ListLinePlot[Thread[{distance, trial1[[;; -2]]}]]

plot

Of course if the data are trimmed before plotting than

ListLinePlot[Thread[{distance, trial1}]]

will do.

$\endgroup$
  • $\begingroup$ Yet another way: ListLinePlot[Select[Flatten[{distance, trial1}, {{2}, {1}}], Length[#] == 2 &]] $\endgroup$ – J. M. is away Aug 30 '15 at 17:38
  • $\begingroup$ Thank you, m_goldberg for the help! This is very helpful. A follow-up question: how would you create a line or curve of best fit for the graph? $\endgroup$ – michaelchang64 Aug 30 '15 at 19:01
  • $\begingroup$ @GumpyCede. Follow-up questions should be put to the whole community, either by editing the original question or (better) by asking a new question. But I'll give you a hint -- follow this link and click on the links there that mention models or regression. $\endgroup$ – m_goldberg Aug 30 '15 at 20:51
4
$\begingroup$

I removed the last element of trail1 as per comment by @march. Lookup this site: https://stackoverflow.com/questions/16513010/how-to-combine-two-lists-to-plot-coordinate-pairs

distance = {0, 5, 25, 45, 65, 85, 105, 125, 145, 150}; 

trial1 = {0, 0.14, 0.49, 0.94, 1.39, 1.85, 2.43, 3.08, 3.61, 4.31}; 

Partition[Riffle[distance, trial1], 2]

(* {{0, 0}, {5, 0.14}, {25, 0.49}, {45, 0.94}, {65, 1.39}, {85, 1.85}, 
    {105, 2.43}, {125, 3.08}, {145, 3.61}, {150, 4.31}}*)
$\endgroup$

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