0
$\begingroup$

I wanted to simulate a noise model on CCD sensors, so I did as below:

noise[i_, j_] := RandomVariate[PoissonDistribution[50], {20, 20}][[i, j]];
noiseimage = DiscretePlot3D[noise[i, j], {i, 1, 20, 1}, {j, 1, 20, 1}, ExtentSize -> Full]

Then I got an error message "Part::pspec" but the desired image appeared.
What was wrong with my code? Thank you in advance.

$\endgroup$
  • $\begingroup$ Works without error for me on V10.4.1. Have you tried on a fresh kernel to avoid problems with previous assignments? $\endgroup$ – Yves Klett Jun 17 '16 at 15:48
  • $\begingroup$ @YvesKlett I was working on Mathematica 9.0. I've refreshed the kernel before executing the above commands. $\endgroup$ – Taiki Bessho Jun 17 '16 at 16:05
2
$\begingroup$

You are simulating new values everytime you call noise[_,_]. To simulate once and plot that you could rewrite it as:

(noise[i_, j_] = #[[i, j]]) &[RandomVariate[PoissonDistribution[50], {20, 20}]];
noiseimage = DiscretePlot3D[noise[i, j], {i, 1, 20, 1}, {j, 1, 20, 1}, ExtentSize -> Full]

The error message concerning the symbolic part argument is not really an error, just a warning.

$\endgroup$
  • $\begingroup$ I understood your code but arose a question that why you used the pure function #. I thought just eliminating the colon : before the equal sign = in the definition of noise[_,_] is easier and sufficient, i.e. noise[i_, j_] = RandomVariate[PoissonDistribution[50], {20, 20}][[i, j]]; Did I miss something important concepts to write Mathematica codes? $\endgroup$ – Taiki Bessho Jun 17 '16 at 22:41
  • $\begingroup$ @TaikiBessho You are right, the pure function is only needed when using :=. $\endgroup$ – Coolwater Jun 18 '16 at 8:44
  • $\begingroup$ I tried your command above in my Mathematica(ver.9) but I got the error message again... Then, I wonder how should I do for not getting the error message... $\endgroup$ – Taiki Bessho Jul 5 '16 at 11:23
  • $\begingroup$ Or I don't have to mind the error? $\endgroup$ – Taiki Bessho Jul 5 '16 at 12:33
0
$\begingroup$

Simpler and faster is:

ArrayPlot[RandomVariate[PoissonDistribution[50], {20, 20}]]
$\endgroup$
  • $\begingroup$ Yeah, it might be useful for some people. I, however, want to get the noise levels not in grayscale but in heights of rectangular blocks. Anyway, thank you. $\endgroup$ – Taiki Bessho Jun 17 '16 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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