I need to perform a number of operations within a For loop and store the results in an indexed array (without using the Append function)
For examole (to make it simple), I need to find the square of numbers i = 1 to 5 and sore it in y[i].
In precedural languages it would look like:
for i = 1,5,i++,
y(i)=i^2
end
To implement this in Mathematica I tried this code:
For[i = 1, i <= 5, i++,
y[[i]] = i^2;
]
which failed. Is there a way to create such array (y)?
yis not defined, so you can't accessy[[i]]. Try definingybefore and it works (for that, see e.g.ConstantArray). Edit My comment assumes, as you state, that you need to useFor. Otherwise that's much simpler withTable. – anderstood Mar 23 '18 at 16:44For[]loop. Tryy = Range[5]^2. – J. M.'s missing motivation Mar 23 '18 at 16:44Table. – gwr Mar 23 '18 at 16:45Map[]orTable[]as already suggested, if you have a list of images. If you really must loop, useDo[]instead. – J. M.'s missing motivation Mar 23 '18 at 17:09Blur, a whole host ofFilters, etc. – High Performance Mark Mar 23 '18 at 20:33