Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I often have the following notebook in Mathematica, which I use to make a dataset and associated errors:

x = {0, 2, 4, 6, 10, 20};
y = {979, 146, 141, 157, 187, 274};
uncY = Sqrt[y];
dataVector = Thread[{x, y}];

I want to make an ErrorListPlot, so I need to add ErrorBar with each uncY-value as an element in each data pair. So the final dataVector should have the form

{{x_i, y_i}, Errorbar[uncY_i]}

What is an easy way to achieve this, without using a For-loop?

share|improve this question
    
@andre why is that? is it too specific? –  BillyJean Mar 23 '13 at 21:29
add comment

2 Answers 2

up vote 6 down vote accepted

If your errors input has the form :

errorList = {1, 2, 1, 3, 1, 2}

Then do :

Thread[{dataVector, Errorbar /@ errorList}]  

(* {  
 {{0, 979}, Errorbar[1]},
 {{2, 146}, Errorbar[2]},
 {{4, 141}, Errorbar[1]},
 {{6, 157}, Errorbar[3]},
 {{10, 187}, Errorbar[1]},
 {{20, 274}, Errorbar[2]}
 } *)
share|improve this answer
add comment

You can do all the manipulation in one line if you wish:

ErrorListPlot@MapThread[{{#1, #2}, ErrorBar[#2-uncY@#2 ]} &, {x, y}]
share|improve this answer
    
I would thumb-up if I had sufficient reputation –  BillyJean Mar 23 '13 at 21:30
    
I'll take a virtual thumbs up, cheers ;) –  image_doctor Mar 24 '13 at 0:32
add comment

Your Answer

 
discard

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.