Hi Antonio,
Here is one method. I took your code as written and combined your calculations for a single radius value into a function that accepts r and produces the calculation. Then this is used in a Table expression to produce a list of data pairs. I suggest reading up on function definitions and Module. Also note that rather than the range expression Table would also accept a list of values for radius.
This is for me a common methodology. I develop a single calculation, cell by cell, and then Merge the cells into a single cell defining a function. Then use Table or Map to evaluate the function repeatedly for a range or list of data items or values. I attach a revised notebook.
Best, David
(* Build a function to determine encircled energy from r *)
encircledEnergy[r_] := Module[
{disk, dat, list},
disk = ColorConvert[
ColorNegate@
Graphics[{Black, Disk[ct, r]}, ImageSize -> {w, h},
PlotRange -> {{0, 1000}, {0, 1000}}], "Grayscale"];
dat = disk // ImageData; list = Position[dat, 1.];
Apply[Plus, Extract[i // ImageData, list]]
]
(* now build a table of values *)
results =
Table[{radius, encircledEnergy[radius]}, {radius, 0, 500, 25}];
ListLinePlot[results, PlotMarkers -> {Automatic, 10},
PlotLabel -> "Encircled Energy", PlotTheme -> "Scientific",
FrameLabel -> {"Radius", "Sum of Intensities"}, ImageSize -> 500,
LabelStyle -> 16]
Attachments: