I asked a similar question here the other day, but I could not make myself clear. Then I ask once again.

I wanted to visualize a noise model on CCD sensors by Mathematica (Mine is ver.9). The following was what I executed:

noise := RandomVariate[PoissonDistribution[10], {20, 20}];
plotnoise = DiscretePlot3D[noise[[i, j]], {i, 1, 20}, {j, 1, 20}, ExtentSize -> Full]

I got an error message besides the expected plot: Part::pspec.

What does the error message mean?
How can I circumvent the error?

Furthermore, I'm thinking to use Manipulate to simulate the effect of stacking of a lot of noise frames and embed it on my web page by use of Wolfram CDF:

noisemean[n_Integer] := Total[Table[noise, {n}]]/n;
noisestack = Manipulate[DiscretePlot3D[noisemean[m][[i, j]], {i, 1, 20}, {j, 1, 20}, ExtentSize -> Full], {m, 1, 256, 1, Appearance -> "Labeled"}]

So, definitely I want to remove the error.

  • $\begingroup$ I cannot reproduce your error in MMA 10.4.0. This is my result when I run the first portion of your code: image. Can you check that the attributes of DiscretePlot3D in your version of Mathematica include a Hold attribute? I.e. report on the result of evaluating: Attributes[DiscretePlot3D]. $\endgroup$ – MarcoB Jul 5 '16 at 17:39
  • 1
    $\begingroup$ @MarcoB The result was {Protected, ReadProtected}. What does it mean? I'm a beginner...sorry $\endgroup$ – Taiki Bessho Jul 5 '16 at 17:45
  • $\begingroup$ @TaikiBessho - are you using version 9? I can reproduce the error in v9 but not v10 $\endgroup$ – Jason B. Jul 5 '16 at 17:50
  • 3
    $\begingroup$ I have a workaround, but I wanted to check why you define your noise with a SetDelayed instead of Set? Every time you call for a value noise[[i,j]], it builds up 400 random numbers only to use one of them. $\endgroup$ – Jason B. Jul 5 '16 at 17:55
  • 2
    $\begingroup$ @MarcoB - If I run Attributes[DiscretePlot3D] from a session where I haven't run DiscretePlot3D, then it returns the 2-element list that Taiki wrote above. But if I ask for the attributes after running a DiscretePlot3D example, then it gives me the HoldAll as well. I get this in version 9 and 10 $\endgroup$ – Jason B. Jul 5 '16 at 18:16

This is similar to the problem you get when you try to use an interpolating function inside a numeric integral, and the solution is similar: Define a helper function that only calls Part when the arguments are both integers:

noise := RandomVariate[PoissonDistribution[10], {20, 20}];
noisefunc[i_Integer, j_Integer] := noise[[i, j]];
DiscretePlot3D[noisefunc[i, j], {i, 1, 20}, {j, 1, 20}, 
 ExtentSize -> Full]

and it works without issue.

I do need to point out that, the way you've written this code, it generates 400 random numbers for every plotted data point. So you are generating $400^2$ random values and only plotting 400 of them. You could either define noise = RandomVariate[PoissonDistribution[10], {20, 20}] instead, or set it up like

 RandomVariate[PoissonDistribution[10]], {i, 1, 20}, {j, 1, 20}, 
 ExtentSize -> Full]

and get the exact same plot.

For the Manipulate, I would do something like this:

   RandomVariate[PoissonDistribution[10], m],
  {i, 1, 20}, {j, 1, 20}, ExtentSize -> Full], {m, 1, 256, 1, 
  Appearance -> "Labeled"}]

enter image description here


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.