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.

Why is the following code not plotting the set of points from {1,1} to {10,10} ?

For[i = 1, i <= 10, i++, Graphics[Point[{i, i}]]]
share|improve this question
1  
Unless an explicit Return is used, the value returned by For is Null. –  chuy Sep 11 '12 at 21:40
add comment

1 Answer

up vote 4 down vote accepted
Graphics[Table[Point[{i, i}], {i, 10}]]

If you want to see the output of your command, modify it a little:

For[i = 1, i <= 10, i++, Print@Framed@Graphics[Point[{i, i}]]]

You will see ten graphics, one point in each one

share|improve this answer
    
also Graphics[Point@Table[{i, i}, {i, 10}]] –  rm -rf Sep 11 '12 at 21:41
    
what I am actually interested in is generating i random points (For seems like a good idea when a number of loop repetitions is known) and then plotting them. Could you give me a hint about this? –  alex Sep 11 '12 at 21:45
    
@alex Put the loop (in Table form) inside the Graphics –  Sjoerd C. de Vries Sep 11 '12 at 21:46
1  
@alex So something like: Graphics[Point@RandomReal[1, {100, 2}]]? –  rm -rf Sep 11 '12 at 21:47
    
I managed to make it work with something like: ListPlot[Table[{RandomReal[{startRange, endRange}], RandomReal[{min, max}]}, {pointsCount}]]. Thanks –  alex Sep 11 '12 at 22:17
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.